User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:ferror
click
to support this page (eg 0,42 € or so) Thanks.

ferror

    int ferror(FILE *stream);

the function ferror tests the error indicator for the stream pointed to by stream, returning non-zero if it is set. The error indicator can only be reset by the clearerr function. Returns non-zero if error indicator is set for stream stream.

C Sourcecode Example

/* 
 * ferror example code
 * http://code-reference.com/c/stdio.h/ferror
 */
 
#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) {    
    printf ("its all fine\n");
    putc('X',handle);
    if (ferror(handle)) { printf ("error in writing to file\n");} 
    fclose (handle);
  } else {
    perror ("error opening file for reading\n");
  }
  return 0;
}

ferror output

if the test.txt does not exist

  output: ./ferror 
  error opening file for reading
  : No such file or directory

if the test.txt exists

  output: ./ferror 
  its all fine
  error in writing to file
  
advertising
c/stdio.h/ferror.txt · Last modified: 2013/07/26 11:32 by 59.120.74.67

Impressum