<PAGE178>
#include <stdio.h >
char *fgets(char *restrict buf, int n,FILE *restrict fp)
fgets():
Line-at-a-time input (每次仅读取一行输入的函数))
buf:
the buffer to read the line into(内存空间,用于存放读取到的一行数据)
n:
sizeof line(一行数据的总数)
fp:
the specified stream
return:
buf if OK, NULLon end of file or error
remarks:
This function reads up through and including the next newline,but no more than n–1 characters, into the buffer(猜测fgets应该是以读取到\r\n来结束)
The buffer is terminated with a null byte
If theline, including the terminating newline , only a partial line is returned(可见在一行中若出现null的结束符,fgets会提前返回buffer数据)
Summarize:
1. fgets以\r\n作为一行结束的标志
2. 一行数据当中若出现null结束符,fgets会提前返回buffer数据