title: Python 2D array i C using ctypes
body: <p>i'm trying to use a self written c lib to proces 2d array from python but with little success.</p>
  
  <p>Here is my c code:</p>
  
  <p>CamLibC.c</p>
  
  <pre><code>int TableCam(const int x, const int y, int **Array) {
      int i = 0;
      int j = 0;
  
      for (i; i &lt; x; i++) {
          for (j; j &lt; y; j++) {
              Array[i][j] = 1;
          };
  
      };
  }
  </code></pre>
  
  <blockquote>
    <p>cc -nostartfiles -shared -fPIC -o CamLibOS.os CamLibC.c</p>
  </blockquote>
  
  <p>Now here is my python wrapper:</p>
  
  <p>CamLibPy.py</p>
  
  <pre><code>import os,sys
  import ctypes
  
  dirname     = os.path.dirname(os.path.realpath(sys.argv[0]))
  CamLibFile  = dirname + '/CamLibOS.os'
  
  _CamLib = ctypes.CDLL(CamLibFile)
  _CamLib.TableCam.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
  
  def TableCam (A) :
      global _CamLib
  
      x = len(A)
      y = len(A[0])
  
      print('x: ', x, ' y: ', y);
  
      arrayType = ((ctypes.c_int * x) * y)
      array = arrayType()
  
      _CamLib.TableCam(ctypes.c_int(x), ctypes.c_int(y), array)
  
      print(array)
  </code></pre>
  
  <p>And my python code where i use the function:</p>
  
  <p>Test.py</p>
  
  <pre><code>import CamLibPy
  from numpy import zeros
  
  Anum = zeros((3,3))
  print('Start: ', Anum)
  
  CamLibPy.TableCam(Anum)
  
  print('Ended: ', Anum)
  </code></pre>
  
  <p>In this test program i try to change all the zeros in the array to ones. but as soon as i try to run this is get the following output:</p>
  
  <blockquote>
    <p>Start:  [[ 0.  0.  0.]  [ 0.  0.  0.]  [ 0.  0.  0.]] </p>
    
    <p>x:  3  y:  3</p>
    
    <p>Traceback (most recent call last):   File "/media/pi/USB
    DISK/Test/Test.py", line 7, in 
        CamLibPy.TableCam(Anum)   File "/media/pi/USB DISK/Test/CamLibPy.py", line 21, in TableCam
        _CamLib.TableCam(ctypes.c_int(x), ctypes.c_int(y), array) ctypes.ArgumentError: argument 3: : expected
    LP_c_long instance instead of c_long_Array_3_Array_3</p>
  </blockquote>
  
  <p>it's saying it expected a c_long but i clearly used c_int to make the arrayType</p>
  
  <p>Can somebody tell me what i did wrong?</p>