I am writing a C program that use fgets to read in each line from a file. The problem is that if the file have a blank line, how to skip it to get the next line ? This is what I had try so far but it did not work.
char line[100];
FILE *filePtr = fopen(filename, "r");
while(fgets(line, sizeof(line), filePtr) != NULL) //read each line of the file
{
if (line != "
")
{
//do something
}
else
{
continue;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…