I have tried to send a python list to a C array of string/integers. And I tried to print the array of string but it is printing nothing.
I am actually writing code to extract data from a .csv file by using Python and trying to send this data to a C code. When I am trying to run the code I am getting some warning.
I am calling this function from main(){}
like string_arr_conversion(NULL,pFunc)
, but I am not able to see any print and I am getting the warning which below explained.
I have debugged and found that if(!PyArg_ParseTuple(args, "o", &str_arr)) {retun NULL;}
when I am calling the function the above if block returning null.
#include <Python.h>
static PyObject *string_arr_conversion(PyObject *self,PyObject *args){
PyObject *str_arr;
int i;
if(!PyArg_ParseTuple(args, "o", &str_arr)){
retun NULL;
}
int n=PyObject_Length(str_arr);
if(n<0) {
return NULL;
}
char arr[n][40];
for(i=0; i<n;i++){
PyObject *str=PyList_GetItem(str_arr,i);
arr[i][40]=PyLong_FromString(str,NULL,10);
}
for(i = 0; i<n; i++){
printf("\n Element is %c", arr[i]);
}
return arr;
}
I am getting the following warnings:
1.In string_err_conversion function passing argument 1 of 'PyLong_FromString' from incompatible pointer type.
note: expected 'char *' but argument is of type 'struct PyObject *'
assignment makes integer from pointer without cast.{here arr[i][MAX_STRING_SIZE]=PyLong_FromString(str,NULL,10); warnings are coming}
2.return from incompatible pointer type and function returns address of local variable.{In this line ::return arr;}