C语言读取文件一行以及换行符的问题
(2010-08-07 11:58:36)
标签:
c换行读文件一行 |
分类: 实验室 |
记下来免得自己忘了。
char *fgets(
The fgets function reads a string from the input stream argument and stores it in str. fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n – 1, whichever comes first. The result stored in str is appended with a null character. The newline character, if read, is included in the string.
fgets从流的当前位置读取字符存到str中,碰到行尾、文件尾或者读到了n-1个字符就停止读取,并在存储的字符串末尾加上null字符作为字符串的结尾(读n-1个字符,加上null字符正好n个)。如果读到了换行符,也会将其存入str中。
对于换行符,msdn介绍fread时说了 :If the given stream is opened in text mode, carriage return–linefeed pairs are replaced with single linefeed characters. The replacement has no effect on the file pointer or the return value.