非常教程

C参考手册

文件输入/输出 | File input/output

clearerr

在头文件<stdio.h>中定义

void clearerr(FILE * stream);

重置EOF给定文件流的错误标志和指示符。

参数

-

该文件重置错误标志

返回值

(没有)。

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
 
int main(void)
{
    FILE* tmpf = tmpfile();
    fputs("abcde\n", tmpf);
    rewind(tmpf);
    int ch;
    while ((ch=fgetc(tmpf)) != EOF)
          printf("%c", ch);
    assert(feof(tmpf)); // the loop is expected to terminate by eof
    puts("End of file reached");
 
    clearerr(tmpf);  // clear eof
 
    if (feof(tmpf))
        puts("EOF indicator set");
    else
        puts("EOF indicator cleared\n");
}

输出:

abcde
End of file reached
EOF indicator cleared

参考

  • C11标准(ISO / IEC 9899:2011):
    • 7.21.10.1清晰器功能(p:338)
  • C99标准(ISO / IEC 9899:1999):
    • 7.19.10.1清晰器功能(p:304)
  • C89 / C90标准(ISO / IEC 9899:1990):
    • 4.9.10.1更清晰的功能
C

C 语言是一门通用计算机编程语言,应用广泛。C 语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。