I'm trying to read line by line from a text file
Code:
FILE *fp;
fp = fopen("airport.txt","r");
if (fp == NULL)
{
exit(1);
}
char dispose[256];
fgets(dispose,256,fp);
printf("%s\n",dispose);
Layout of text file: airport.txt
Airport City/State Population Lat Lon
BHM Birmingham,Alabama 231483 33.5639 86.7522
ABC Los Angeles, California
The problem is: Fgets does not stop after the 1st line. It continues reading until 256 characters are read.
Is my textfile somehow missing a '\n'? I think Fgets cannot detect a newline char, thus it continues reading until EOF. Is it possible for a textfile to be missing newline?
"The fgets() function reads up to the first newline it encounters, or stops when it runs out of space to store the result, or when it gets EOF (so there is no more data to read)."