clearerr

Defined in header <stdio.h>
void clearerr( FILE *stream );

Resets the error flags and the EOF indicator for the given file stream.

Parameters

stream - the file to reset the error flags for

Return value

(none)

Example

#include <stdio.h>
#include <assert.h>
 
int main(void)
{
    FILE* tmpf = tmpfile();
    fputs("cppreference.com\n", tmpf);
    rewind(tmpf);
 
    for (int ch; (ch = fgetc(tmpf)) != EOF; putchar(ch)) { }
 
    assert(feof(tmpf)); // the loop is expected to terminate by EOF
    puts("End of file reached");
 
    clearerr(tmpf); // clear EOF
 
    puts(feof(tmpf) ? "EOF indicator set" 
                    : "EOF indicator cleared");
}

Output:

cppreference.com
End of file reached
EOF indicator cleared

References

See also

feof
checks for the end-of-file
(function)
perror
displays a character string corresponding of the current error to stderr
(function)
ferror
checks for a file error
(function)
C++ documentation for clearerr

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/c/io/clearerr