clearerr函数
概要:
#include <stdio.h>
void clearerr(FILE *stream);
描述:
该函数清除参数stream指向流的文件末尾指示符和错误指示符。
参数:
FILE *stream
指向一个打开的流的指针。
返回值:
无。
范例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*函数clearerr范例*/
#include <stdio.h>
#include <stdlib.h>
void testEof(FILE *stream)
{
if(feof(stream))
puts("The end-of-file indicator is set.");
else
puts("The end-of-file indicator is not set.");
}
int main(void)
{
FILE *pFile;
/*打开文件。*/
pFile = fopen("gch.txt", "r");
if(!pFile)
{
perror("Error");
exit(EXIT_FAILURE);
}
/*生成文件末尾指示符。*/
while(fgetc(pFile) != EOF)
;
/*测试文件末尾指示符。*/
testEof(pFile);
/*清除文件末尾指示符。*/
clearerr(pFile);
/*再次测试文件末尾指示符。*/
testEof(pFile);
/*关闭文件。*/
fclose(pFile);
return 0;
}
|
输出:
The end-of-file indicator is set.
The end-of-file indicator is not set.
相关内容: