int k;
char string[100];
for(k = 0; k < MAX_STATIONS; k++){
fgets(string,100,fp);
printf("%s", string);
}
So I've got my sniped of code here, and when I try to print the text from the file, the last line is either repeated maybe 10 times.
195 11.00 2013 11 02 15 32 49.76668 234.97289 30
196 11.40 2013 11 02 15 32 49.70103 235.04120 30
197 7.30 2013 11 02 15 32 48.52185 236.57961 5
199 10.00 2013 11 02 15 32 48.39511 236.69492 5
200 8.50 2013 11 02 15 32 48.48800 236.67270 5 200 8.50 2013 11 02 15 32 48.48800 236.67270 5 200 8.50 2013 11 02 15 32 48.48800 236.67270 5 200 8.50 2013 11 02 15 32 48.48800 236.67270 5 200 8.50 2013 11 02 15 32 48.48800 236.67270 5
That is my output, any help would be much appreciated. Also, I'd like a bit of clarification, what do we do with the middle part of fgets(string,100,fp) (100 in this case).
Thanks
EDIT: I seem to have solved the problem by adding
if(feof(fp)) break;
Is that a valid solution?
EDIT2: I have also solved it by putting a while loop to check if it has reached the end of the stream within the forloop:
int k;
char string[100];
for(k = 0; k < MAX_STATIONS; k++){
while(!feof(fp)){
fgets(string,100,fp);
printf("%s", string);
//if(feof(fp)) break;
}
}