A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.cplusplus.com/reference/cstdio/clearerr/ below:

function

<cstdio>

clearerr
void clearerr ( FILE * stream );

Clear error indicators

Resets both the error and the eof indicators of the stream.

When a i/o function fails either because of an error or because the end of the file has been reached, one of these internal indicators may be set for the stream. The state of these indicators is cleared by a call to this function, or by a call to any of: rewind, fseek, fsetpos and freopen.



Parameters
stream
Pointer to a FILE object that identifies the stream.

Return Value None

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* writing errors */
#include <stdio.h>
int main ()
{
  FILE * pFile;
  pFile = fopen("myfile.txt","r");
  if (pFile==NULL) perror ("Error opening file");
  else {
    fputc ('x',pFile);
    if (ferror (pFile)) {
      printf ("Error Writing to myfile.txt\n");
      clearerr (pFile);
    }
    fgetc (pFile);
    if (!ferror (pFile))
      printf ("No errors reading myfile.txt\n"); 
    fclose (pFile);
  }
  return 0;
}

This program opens an existing file called myfile.txt for reading and causes an I/O error trying to write on it. That error is cleared using clearerr, so a second error checking returns false.

Output:


Error Writing to myfile.txt
No errors reading myfile.txt


See also
feof
Check end-of-file indicator (function)
ferror
Check error indicator (function)
rewind
Set position of stream to the beginning (function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4