VOOZH about

URL: https://www.geeksforgeeks.org/c/ferror-in-c/

⇱ ferror() in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ferror() in C

Last Updated : 3 Feb, 2025

In C, ferror() is a built-in function used to check errors in files during file operations. It provides a simple way to do file operations without any interruption in your C program.

Syntax

ferror() is a standard library function defined in <stdio.h> file.

ferror(fptr)

Parameter:

  • Take as a file stream in parameter.

Return Value:

  • If the file has error, it returns a non-zero value.
  • Otherwise, it returns 0.

Note: To check error in file using ferror(), file must be open before it.

Examples of ferror()

The following examples demonstrate the use of ferror() in C programs.

Check Error When Writing Data


Output
Data written successfully.

Check Error When Read Data


Output
GeeksForGeeks!
No error, Data read successfully
Comment
Article Tags: