I'm having trouble with multiple files opened. File 1 contains a list of data files that I need to open and read from. I open file 1
(fh1 = fopen()) and being a loop in which I read a line from
the file. I use this information to open a second file (fh2=fopen()), read the contents of file 2, close file 2 ( fclose(fh2)) create display based on the information and continue with the next iteration of the loop (reading from file 1). My problem occurs with the fclose(fh2). If I close fh2 my output is not generated, if I do
not close fh2, everything works fine.
Basically here's what I'm doing:
fh1 = fopen(file1, "r");
while ( input = fgets(fh2) ) {
fh2 = fopen(input, "r")
while (datatomanipulate = fgets(fh2) ) {
// save data
}
fclose(fh2);
// generate output, using PRINT()
}
fclose(fh1);
if I omit the flcose(fh2) call, everything works. If I leave in the
call I do not get the output (either using PRINT or ECHO).
Anyone have any ideas why closing the inner file causes problems?
Thanks.