I am trying to use a C library in Python using SWIG. This C library passes function results through arguments everywhere. Using the online SWIG manual, I have succeeded in getting an integer function result passed to Python, but I am having a hard time figuring out how to do this for a character string.
This is the essence of my code:
myfunc.c:
#include <myfunc.h>
#include <stdio.h>
int mystr(int inp, char *outstr){
outstr="aaa";
printf("%s\n", outstr);
return(0);
}
myfunc.h:
extern int mystr(int inp, char *outstr);
So basically my question is what the typemap for *outstr should look like.
Thanks in advance.
outstr="aaa";? I suspect you meantstrcpy(outstr,"aaa");.outstr="aaa";wouldn't change the string that the caller passes in. Theoutstrparameter is treated as a local variable in the function, sooutstr="aaa";just makes the localoutstrpoint to an unnamed, initialized array of 4 characters{ 'a', 'a', 'a'. '\0' }.