Help us and donate little Bitcoins to pay the server costs: 1AXLPuRUBYc1JczTW4XS65GL6oWjNP2Vt2

User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer







because of the inhumane working conditions at amazon in Germany, I will offer the Amazon app no more! (ARD Reportage)
c:stdio.h:clearerr

clearerr

    void clearerr(FILE *stream);

Description

The clearerr function resets the error flags and EOF indicator for the given stream.
When an error occurs, you can use |perror()| to figure out which error actually occurred.

clearerr C Sourcecode Example

/* 
 * clearerr example code
 * http://code-reference.com/c/stdio.h/clearerr 
 */
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
 
int main( void )
{
  FILE *handle;
  handle = fopen("test.txt","r");
 
  if (handle!=NULL)
  {
    fputc ('X',handle);
    if (ferror (handle) == 1 ) {
          printf ("error in writing to test.txt\n");
          clearerr (handle);
        }
 
    fgetc (handle);
    if (ferror (handle) == 0)
      printf ("its all fine\n"); 
    fclose (handle);
  }
  else {
           printf ("error opening file for reading");
       }
  return 0;
}

clearerr output for this example code

  output: ./clearerr 
  error in writing to test.txt
  its all fine

see also

advertising
c/stdio.h/clearerr.txt · Last modified: 2013/01/22 22:02 (external edit)

The new Question & Answer System is online and waiting for your Questions about Programming problems http://ask.code-reference.com Impressum