首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求教判断一个文件中某行是不是空行的有关问题.

2012-03-23 
求教判断一个文件中某行是不是空行的问题...其实我是从文件中fgets读入,文件中有空行.怎么判断是不是空行?

求教判断一个文件中某行是不是空行的问题...
其实我是从文件中fgets读入,文件中有空行.怎么判断是不是空行?
我用了好多判断字符串为空的方法都不行...(比如strlen(buf)   ==   0,   buf   == " ",buf==NULL),就是判断不出来,请教高手!!主要是想判断是不是空行!

[解决办法]
判断 buf[0] == '\n ' 或 buf[0] == '\0 ' (文件最后一行也许没回车)

char * fgets ( char * str, int num, FILE * stream );

<cstdio>

Get string from stream

Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first.
A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str.
A null character is automatically appended in str after the characters read to signal the end of the C string.

热点排行