Which method can be used to read one line at a time from a file in C?
I am using the fgets function, but it\'s not working. It\'s reading the space
Use fgets to read from the line, and then use getc(...) to chew up the newline or end-of-line to continue reading....here's an example of forever reading a line...
// Reads 500 characters or 1 line, whichever is shorter
char c[500], chewup;
while (true){
fgets(c, sizeof(c), pFile);
if (!feof(pFile)){
chewup = getc(pFile); // To chew up the newline terminator
// Do something with C
}else{
break; // End of File reached...
}
}