C extension/char array question

Bob Greschke bob at passcal.nmt.edu
Mon Dec 3 19:04:59 EST 2001


In C I'm doing something like

   char *Array = {"THIS", "THAT"};

in the main function, then I do something like RememberMe(Array); to a
function like

   void Remember(TheArray)
   char *TheArray[];
   {

/* RememberMe is, let's say, some sort of global (char **RememberMe)
*/
      RememberMe = TheArray;
   }

then in another library function I read in a line of text from a file
and

   for (i = 0; i < 2; i++)
   {
      if (strstr(InLine, RememberMe[i]) != (char *)NULL)
         break;
   }
   check to see if there was a match or not, blah, blah, blah

What I want to be able to do is code the list of things to look for
("THIS" and "THAT") into the Python part, and call a C extension
function that calls the C library function that does the job of
RememberMe().  I guess I'm not sure what to put "THIS" and "THAT" into
(a list?), and what format specifier to use in  PyArg_ParseTuple(), to
make sure that C is able to keep track of the addresses of the char
array elements so it can use them in the strstr() function -- if this
can be done in a straightforward manner at all.  Will I have to
'recreate' the array of strings in the extension, like with malloc()?
I've written extensions to pass floats and ints back and forth, but
not arrays of arrays.

Thanks!

Bob






More information about the Python-list mailing list