我正在写一个C程序,它使用fgets从文件中读取每一行。问题是,如果文件有一个空行,如何跳过它来获得下一行?这是我到目前为止的尝试,但没有奏效。fgets跳过空行
char line[100];
FILE *filePtr = fopen(filename, "r");
while(fgets(line, sizeof(line), filePtr) != NULL) //read each line of the file
{
if (line != "\n")
{
//do something
}
else
{
continue;
}
}
谢谢,它现在工作。但我不明白,增加行数组是因为我应该像'for(i = 0; i
user4075830
2014-09-26 04:32:11