Originally Posted by
andrew.bolster
Made all changes noted above, and its still not decending into the while loop, so the pointers must be screwing up somewhere, but i dont understand why.
Each time i create a new pointer, assign it to the original file pointer, so as far as i understand it, thats two separate pointers pointing to the same original file location.
Then i take the copy, and mess around with it, so the original should still be the same?
Compare the following code:
Code:
#include <stdio.h>
#include <stdlib.h>
void readfile(FILE *fileptr) {
FILE *ip;
char nextfive[6];
ip = fileptr;
fgets(nextfive, 6, ip);
printf("%s\n", nextfive);
}
int main(void) {
FILE *infile;
infile = fopen("test.txt", "r");
readfile(infile);
readfile(infile);
readfile(infile);
fclose(infile);
return 0;
}
(Note the copying of file pointers inside the function.) Tell me what you think it does, then run it and see what it does.