C语言-文件 *** 作

C语言-文件 *** 作,第1张

1.总览

Index函数名用途描述与说明返回值
1rewind设置文件位置指示器到文件的开头,等价于(void) fseek(stream, 0L, SEEK_SET)没有返回值
2feof测试指向的流中的文件结束标记,如果已设置就返回非零值。


这个函数不应当失败,它不设置外部变量 errno 。


(但是,如果 fileno 检测到它的参数不是有效的流,它必须返回 -1,并且将 errno 设置为 EBADF 。


)

3ftell获取当前文件位置指示若成功则为当前文件位置指示,若出错则为-1L
4fgets

fgets函数读入数据,直到行结束或缓存满(当然会留出一个字节存放终止字符).

2.分述

2.1 rewind

#include 
void rewind(FILE *stream);
The rewind() function sets the file position indicator for the stream pointed to by 
stream to the beginning of the file.  It is equivalent to: 
(void) fseek(stream, 0L, SEEK_SET)
The rewind() function returns no value.

2.2 feof

tests the end-of-file indicator for the stream pointed to by stream.
测试指向的流中的文件结束标记,如果已设置就返回非零值。


文件结束标记只能用函数clearerr清除.

2.3 ftell

The ftell() function obtains the current value of the file position indicator for the 
stream pointed to by stream.


The rewind() function returns no value.  Upon successful completion, fgetpos(), 
fseek(),fsetpos() return 0, and ftell() returns the  current  offset.  Otherwise,
-1 is returned and errno is set to indicate the error.

2.4 fgets

#include 
char *fgets(char *s, int size, FILE *stream);

fgets() reads in at most one less than size characters from stream and stores them 
into the buffer pointed to by s.  Reading stops after an EOF  or a newline.  
If a newline is read, it is stored into the buffer.  A terminating null byte ('\0') 
is stored after the last character in the buffer.

gets() and fgets() return s on success, and NULL on error or when end of file occurs 
while no characters have been read.

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/634965.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-16
下一篇 2022-04-16

发表评论

登录后才能评论

评论列表(0条)

保存