unix环境高级编程-5.7-每行一次I/O
2011-11-06 19:00
113 查看
下面两个函数提供每次输入一行的功能
两个返回值:若成功返回buf,若已达到文件结尾或出错则返回NULL;
char * fgets (char *s, int count, FILE *stream) [Function]
The fgets function reads characters from the stream stream up to and including a
newline character and stores them in the string s, adding a null character to mark
the end of the string. You must supply count characters worth of space in s, but the
number of characters read is at most count
这两个函数都指定了缓冲区的地址。读入的行将送入其中。gets从标准输入读,而fgets则从指定的流读。
而对于fgets,必须指定缓冲区的长度n,此函数一直读到下一个换行符为止。但不超过n-1个字符。
#include<stdio.h> char *fgets(char * restrict buf,int n,FILE* restrict fp); char* gets(char* buf);
两个返回值:若成功返回buf,若已达到文件结尾或出错则返回NULL;
char * fgets (char *s, int count, FILE *stream) [Function]
The fgets function reads characters from the stream stream up to and including a
newline character and stores them in the string s, adding a null character to mark
the end of the string. You must supply count characters worth of space in s, but the
number of characters read is at most count
这两个函数都指定了缓冲区的地址。读入的行将送入其中。gets从标准输入读,而fgets则从指定的流读。
而对于fgets,必须指定缓冲区的长度n,此函数一直读到下一个换行符为止。但不超过n-1个字符。
相关文章推荐
- UNIX环境高级编程学习之第三章文件IO-文件读偏移操作
- unix环境高级编程-线程控制(2)
- <unix 环境高级编程> 环境配置
- unix环境高级编程--IO
- UNIX环境高级编程学习之第七章进程环境-存储器分配malloc
- unix环境高级编程-进程间通信
- unix环境高级编程第三版源代码编译及使用
- unix环境高级编程-互斥量机制
- UNIX环境高级编程——线程同步之互斥量
- unix环境高级编程之线程篇(一)
- UNIX环境高级编程之第9章:进程关系
- UNIX环境高级编程:第七章:进程环境
- unix环境高级编程(阅读笔记)------signal函数与sigaction的区别
- UNIX环境高级编程 第十五章:进程间通信:是指在不同进程之间传播或交换信息
- UNIX环境高级编程——线程和fork
- UNIX环境高级编程第三版源码编译
- UNIX:高级环境编程 - 第十五章 IPC:进程间通信
- UNIX环境高级编程——进程管理和通信(总结)
- UNIX环境高级编程----函数索引(部分)
- (十二) 一起学 Unix 环境高级编程 (APUE) 之 进程间通信(IPC)