fgets读取文本
来源:互联网 发布:淘宝客内部优惠券源码 编辑:程序博客网 时间:2024/05/18 02:19
char * fgets ( char * str, int num, FILE * stream );
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 the end-of-file is reached, whichever happens first.
A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str.
A terminating null character is automatically appended after the characters copied to str.
Notice that fgets is quite different from gets: not only fgets accepts a stream argument, but also allows to specify the maximum size of str and includes in the string any ending newline character.
Parameters
str
Pointer to an array of chars where the string read is copied.
num
Maximum number of characters to be copied into str (including the terminating null-character).
stream
Pointer to a FILE object that identifies an input stream.
stdin can be used as argument to read from the standard input.
Return Value
On success, the function returns str.
If the end-of-file is encountered while attempting to read a character, the eof indicator is set (feof). If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str remain unchanged).
If a read error occurs, the error indicator (ferror) is set and a null pointer is also returned (but the contents pointed by str may have changed).
Example
char line[1024] = {'\0'};
fopen...
while (1)
{
if (fgets(line, sizeof(line), fp) == NULL)
{
break;
}
//do something on line buffer
}
fclose...
- fgets读取文本
- fgets读取文本内容的一行,如何去掉回车符
- fgets读取一行数据
- fgets()读取一行数据
- fgets()读取一行数据
- fgets() -- 读取文件的一行
- c文件读取之fgets
- fgets()逐行读取文件内容
- 文件读取函数fgets和fputs
- 读取文本
- 读取文本
- 读取文本
- 读取文本
- 读取文本
- fgets
- fgets
- fgets
- fgets()
- 最通俗易懂的KMP算法
- 1020. Big Integer
- R画闪点图
- Linux动态库的编译与使用
- 2.2.1新增-contentEditable属性
- fgets读取文本
- android设计模式--之观察者模式(Observer)
- KBEngine0.1.13-源码+客户端-配置过程记录(详细)
- 自定义控件---带边框的圆形图片
- Android应用开发:CardView的使用及兼容
- Java中匿名内部类 只能访问外部类变量
- JAVA环境配置
- Redis inset内部结构
- Python 正则表达式验证字符串