Discarding blank lines?
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:
This works when I have many blank lines in the document, but it doesn't catch trailing blank lines.
fgets(buf, 255, fp_fileNamesCheck);
if (strlen(buf) > 1)
Ex, it catches
but doesn't catch
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 == '\n'.
This is also C, not C++.