title: Python using ctypes to pass a char * array and populate results
body: <p>I'm trying to use ctypes to create a char * array in python to be passed to a library for populating with strings. I'm expecting 4 strings back no more than 7 characters in length each.</p>
  
  <p>My py code looks like this</p>
  
  <p><strong>testlib.py</strong></p>
  
  <pre><code>from ctypes import *
  primesmile = CDLL("/primesmile/lib.so")
  
  getAllNodeNames = primesmile.getAllNodeNames
  getAllNodeNames.argtypes = [POINTER(c_char_p)]
  results = (c_char_p * 4)(addressof(create_string_buffer(7)))
  err = getAllNodeNames(results)
  </code></pre>
  
  <p><strong>lib.cpp</strong></p>
  
  <pre><code>void getAllNodeNames(char **array){
      DSL_idArray nodes; //this object returns const char * when iterated over
      network.GetAllNodeIds(nodes);
      for(int i = 0; i &lt; (nodes.NumItems()); i++){
      strcpy(array[i],nodes[i]);
      }
  }
  </code></pre>
  
  <p>I keep getting segmentation faults when I try to run this code. I've created a test from C that works perfectly but in Python I must be setting up the pointer array incorrectly or something. It seems to get to the second node in the loop and then have a problem as I've seen from spitting out data into the command line. Any insight would be much appreciated.</p>