-
Discarding blank lines?
Hey,
I'm writing a program that takes input from a file called index.txt. I want to be able to discard blank lines. This is what I have:
Code:
while (!feof(fp_fileNamesCheck))
{
char buf[256];
fgets(buf, 255, fp_fileNamesCheck);
if (strlen(buf) > 1)
newNamesCount++;
}
This works when I have many blank lines in the document, but it doesn't catch trailing blank lines.
Ex, it catches
|File1
|File2
|
|
|
but doesn't catch
|File1
|File2
|
Any help would be appreciated. Thanks.
-
Read the FAQ on why using feof() to control a loop is bad.
Use the return result of fgets() instead.
-
Better to just check if buf[0] == '\n'.
This is also C, not C++.
-