clearerr - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# clearerr

From cppreference.com
< c‎ | io

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

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

### [edit] Parameters

stream | - | the file to reset the error flags for

### [edit] Return value

(none)

### [edit] Example

Run this code

    #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");
    }

Output:

    abcde
    End of file reached
    EOF indicator cleared

### [edit] References

- 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

### [edit] See also

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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/io/clearerr&oldid=84358"