help with reading from stream
Hello fellow C lovers. I have a questions concerning reading from a stream.
Im reading filenames out of a file like this text file:
file.txt
-------------------
filename1\n
filename2\n
etc.
-------------------
Im using this loop for now:
Code:
char filename[100];
int c, i = 0;
FILE *fp;
while ( (c = fgetc(fp)) != EOF) {
if (c != '\n')
filename[i++] = c;
else
break;
filename[i] = '\0';
/* here I open another file and use another while() loop
reading chars with fgetc and fputc() those chars into
a different fp */
}
My question is: It seems (going through gdb) that while in this loop
if I open another fp and do something and then come back to
the top of the loop to continue getting characters from the other
fp, the fp points back to the beginning of the stream and not to where
I left off in that stream. Is this normal, and is there a way to prevent
this?
Thanks :)