I am calling a Python program from C code using the system() call inside a Linux machine.
Let's say the first call to the Python program reads the first 10 lines of some text file by opening the text file and reading lines 1 - 10. Now during the second call to the Python program, I want to read the next 10 lines 11-20 of the same text file that was opened during the last call to Python WITHOUT reopening the file and starting from the first line of the file. During the 3rd call to the Python program, I want to be able to read the next 10 lines 21 - 30 of the same text file WITHOUT reopening the file and starting from the beginning of the file. This goes on ...
Here is the sample code
//This is C code
...
...
int initial_line_number, final_line_number
initial_line_number = 1;
final_line_number = 10;
for(i = 1; i <= 10; i++)
{
system("python test.py initial_line_number, final_line_number"); //test.py reads a text file from initial_line number to final_line_number
initial_line_number += 10;
final_line_number +=10;
}
Can this be done? What is the most elegant way to do it?