User Tools

Site Tools


c:stdio.h:clearerr

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:clearerr [2024/02/16 01:05] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +===== clearerr =====
  
 +<code c>
 +    void clearerr(FILE *stream);
 +</code>
 +
 +
 +=== 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 =====
 +<code c>
 +/* 
 + * 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;
 +}
 +</code>
 +
 +==== clearerr output for this example code ====
 +    output: ./clearerr 
 +    error in writing to test.txt
 +    its all fine
 +
 +
 +==== see also ====
 +[[c:stdio.h:feof|feof()]] [[c:stdio.h:ferror|ferror()]] [[c:stdio.h:perror|perror()]] 

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/clearerr.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz