Problem in printing array of char pointer passing from Python
- by Yan Cheng CHEOK
My following C code works quite well, till my Python code trying to pass an array of char pointer to it.
The output I obtain is
The file_name is python-file
Another 3 string is not being printed out. Anything I had missed out?
C Code
#include <iostream>
#include "c_interface.h"
int foo(const char* file_name, const char** names) {
std::cout << "The file_name is " << file_name << std::endl;
while (*names) {
std::cout << "The name is " << *names << std::endl;
names++;
}
return 0;
}
/*
int main() {
const char *c[] = {"123gh", "456443432", "789", 0};
foo("hello", c);
getchar();
}
*/
Python Code
#!c:/Python27/python.exe -u
from ctypes import *
name0 = "NAME0"
name1 = "NAME1"
name2 = "NAME2"
names = ((c_char_p * 1024) * 4)()
names[0].value = name0
names[1].value = name1
names[2].value = name2
names[3].value = 0
libc = CDLL("foo.dll")
libc.foo("python-file", names)