Hello,
gcc 4.4.4 c89
I am reading in a file and in that file I have to do some operation on each line.
In a loop I call a 2 functions that pass in this file pointer to perform 2 different operations on the file.
However, as I am using fgets to read in a line of that text file. It automatically increments to the next line. So for the second call, it has already incremented. However, I want to perform a different operation on the same line as the first function.
FILE *fp = NULL;
fp = fopen("devices.txt", "r");
for each line
get_devicename(fp); <-- calls fgets and operates on line 1, then increments to line 2
get_machine_code(fp); <-- calls gets and already on line 2, I need line 1
end for
To have a work around, I created 2 file pointers objects and passed them to the functions. However, in the future I might need more operations to do on this text file. So not very scalable if I have to keep creating instances of the file pointer.
Many thanks for any suggestions,