title: cTypes - passing a string as a pointer from python to c
body: <p>I'm trying to pass a string (as a pointer) from python to a C function using cTypes.</p>
  
  <p>The c function needs to get a pointer to a string (array of chars) but I haven't successfully got this to work with multiple chars, but my only success(kind of successful, look at the output) is with 1 char and would love for some help!</p>
  
  <p>I need to send a pointer of a string to char - (unsigned char * input)</p>
  
  <p><strong>My Python Code:</strong></p>
  
  <pre><code>def printmeP(CHAR):
      print("In Print function")
      print(CHAR)
      c_sends = pointer(c_char_p(CHAR.encode('utf-8')))
      print("c_sends: ")
      print(c_sends[0])
      python_p_printme(c_sends)
      print("DONE function - Python")
      print(c_sends[0])
      return
  
  
  from ctypes import c_double, c_int,c_char, c_wchar,c_char_p, c_wchar_p, pointer, POINTER,create_string_buffer,  byref, CDLL
  import sys
  
  lib_path = '/root/mbedtls/programs/test/mylib_linux.so' .format(sys.platform)
  
  
  CHAR = "d"
  
  try:
      mylib_lib = CDLL(lib_path)
  except:
       print('STARTING...' )
  python_p_printme = mylib_lib.printme
  python_p_printme.restype = None
  printmeP(CHAR)
  
  
  </code></pre>
  
  <p><strong>My C Code:</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  void printme(char * param) {
      printf("\nStart c Function!\n");
      printf("%s\n Printing param\n ", param);
      char add = '!';
      strncat(param, &amp;add, 1);
  
      printf("%s\n Printing param\n ", param);
      printf("Function Done - c\n");
  }
  </code></pre>
  
  <p><strong>My Output:</strong></p>
  
  <pre><code>In Print function
  d &lt;--- this is what i am sending
  c_sends: 
  b'd' &lt;--- this is after encoding
  ��[� &lt;-------------=|
   Printing param       |
   ��[�               | This is the c code print
   Printing param        | **Question:** Why does it print '�' and no what's supposed to be printed
   Function Done - c &lt;--=|
  DONE function - Python
  b'd!' &lt;--------------------- this is the last print that prints after the change.
  
  </code></pre>
  
  <p>Would love for some help, thanks to everyone that participated :)</p>
  
  <p>sincerely,
  Roe</p>