# clearerr

> C++ Atlas: `cppatlas.com/w/c/io/clearerr` | Source: https://en.cppreference.com/w/c/io/clearerr | Domain: File input/output

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

## Official Specification Summary (cppreference)

```cpp
// 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

```c
#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:

```text
cppreference.com
End of file reached
EOF indicator cleared
```

### References

- C17 standard (ISO/IEC 9899:2018):

  - 7.21.10.1 The clearerr function (p: 246)

- C11 standard (ISO/IEC 9899:2011):

  - 7.21.10.1 The clearerr function (p: 338)

- C99 standard (ISO/IEC 9899:1999):

  - 7.19.10.1 The clearerr function (p: 304)

- C89/C90 standard (ISO/IEC 9899:1990):

  - 4.9.10.1 The clearerr function

### See also

- [`feof`](https://en.cppreference.com/w/c/io/feof): checks for the end-of-file (function)
- [`perror`](https://en.cppreference.com/w/c/io/perror): displays a character string corresponding of the current error to `stderr` (function)
- [`ferror`](https://en.cppreference.com/w/c/io/ferror): checks for a file error (function)
- [C++ documentation for `clearerr`](https://en.cppreference.com/w/cpp/io/c/clearerr)

---
Attribution: content from https://en.cppreference.com/w/c/io/clearerr (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.