clearerr() — Reset Error Indicators
Format
#include <stdio.h>
void clearerr (FILE *stream);
Language Level
ANSI
Threadsafe
Yes
Description
The clearerr()
function resets the error indicator and end-of-file indicator for the specified stream. Once set, the indicators for a specified stream remain set until your program calls the clearerr()
function or the rewind()
function. The fseek()
function also clears the end-of-file indicator. The ILE C/C++ runtime environment does not automatically clear error or end of file indicators.
Return Value
There is no return value.
The value of errno can be set to:
- Value
- Meaning
- EBADF
- The file pointer or descriptor is not valid.
- ENOTOPEN
- The file is not open.
- ESTDIN
stdin
cannot be opened.- EIOERROR
- A non-recoverable I/O error occurred.
- EIORECERR
- A recoverable I/O error occurred.
Example
This example reads a data stream, and then checks that a read error has not occurred.
#include <stdio.h>
#include <stdlib.h>
FILE *stream;
int c;
int main(void)
{
if ((stream = fopen("mylib/myfile", "r")) != NULL)
{
if ((c=getc(stream)) == EOF)
{
if (ferror(stream))
{
perror("Read error");
clearerr(stream);
}
}
}
else
exit(0);
}