Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <stdio.h>
void clearerr(FILE *stream);
#define _OPEN_SYS_UNLOCKED_EXT 1
#include <stdio.h>
void clearerr_unlocked (FILE *stream);
Resets the error indicator and EOF indicator for the stream that stream points to. Generally, the indicators for a stream remain set until your program calls clearerr() or rewind().
clearerr_unlocked() is functionally equivalent to clearerr() with the exception that it is not thread-safe. This function can safely be used in a multithreaded application if and only if it is called while the invoking thread owns the (FILE*) object, as is the case after a successful call to either the flockfile() or ftrylockfile() function.
clearerr() returns no values.
⁄* CELEBC15
This example reads a data stream and then checks that a read
error has not occurred.
*⁄
#include <stdio.h>
int main(void)
{
char string[100];
FILE *stream;
int eofvalue;
stream = fopen("myfile.dat", "r");
⁄* scan an input stream until an end-of-file character is read *⁄
while (!feof(stream))
fscanf(stream,"%s",&string[0]);
⁄* print EOF value: will be nonzero *⁄
eofvalue=feof(stream);
printf("feof value=%i\n",eofvalue);
⁄* print EOF value-after clearerr, will be equal to zero *⁄
clearerr(stream);
eofvalue=feof(stream);
printf("feof value=%i\n",eofvalue);
}