
Originally Posted by
laserlight
Post the smallest and simplest compilable C program that demonstrates the problem, along with the test Python program.
Actually, looking at the first fprintf call I'm guessing that you're writing the Python program from the C program, in which case you should fclose before calling system. But it's only a guess because you chose to post a code snippet without enough context.
Code:
int main(int argc, const char * argv[]) {
if(argc <= 2)return -1;
char file_name[100];
strncpy(file_name, argv[1], 100);
FILE* fp = fopen(file_name, "read");
if(!fp)return -1;
//some irrelevant code
remove("translation.py");
FILE * python_file_pointer = fopen("translation.py", "ab+");
fprintf(python_file_pointer, "list = []\n");
//Do parsing and magic here, which does not matter
fprintf(python_file_pointer, "print(list)\n");
system("python3 translation.py");
fclose(python_file_pointer);
fclose(fp);
}
Problem solved! I have to close first! Thank you!