读书人

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

发布时间: 2012-03-23 12:06:21 作者: rapoo

求教判断一个文件中某行是不是空行的问题...
其实我是从文件中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.

读书人网 >C++

热点推荐