Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeoffflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : ferror

intferror(FILE * stream) ;

Return Type : int

Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
Read about return values of ferror function .

1st Parameter Type : FILE *

Pointer to FILE structure for file operations

1st Parameter

Pointer to the file stream to check for an error condition

Read more about parameters of ferror in parameters section
The ferrorfunction in C language checks if error indicator in the given file streams has been set.
The ferror function is a stream-oriented diagnostic function in C that checks if any error has occurred during I/O operations on a file stream. It's commonly used in conjunction with feof() to determine whether a read/write operation failed due to an actual error (like disk or permission issues) or simply because the end of file was reached. Like feof(), it returns 1 when the respective indicator (error indicator in this case) is set and 0 otherwise, but neither function clears these indicators – that's the job of clearerr(). These functions typically work as a team after failed I/O operations (like fread, fwrite, getc, putc) to properly diagnose and handle the failure cause.

To Summarize the Workflow:
  1. 1.
    Function receives a pointer to a FILE stream (ferror(FILE *stream))
  2. 2.
    Checks the error indicator flag in the stream structure
  3. 3.
    If error indicator is set: Returns 1 (indicating an error occurred in previous operations)
  4. 4.
    If error indicator is not set: Returns 0 (indicating no errors)
  5. 5.
    Does not clear the error indicator - clearerr() must be used for this
  6. 6.
    Does not perform actual error detection - only reports the indicator state


Yes

No

ferror(FILE *stream)

Error indicator set?

Return 1

Return 0




Read more about return type and value offerror function in return section.
The ferrorfunction takes 1 parameter:
  • FILE * `stream`: Pointer to the file stream to check for an error condition
The ferror function return value :
  • ferror function returns a non-zero value if the error indicator is set for the stream,otherwise, it returns zero
    When returns 1 (true):
    An error has occurred during reading/writing operations;
    The error indicator is set on the stream;
    Indicates issues like: I/O errors, disk problems, permission issues;
    If returned 0 (false):
    No errors have occurred;
    The error indicator is not set;
    Stream operations have been working normally;

ferror(FILE *stream) Error indicator set? Return 1 Return 0 Yes No

Output

This example demonstrates the basic usage of `ferror`. It attempts to open a non-existent file, which will likely fail, and then checks for errors using ferror.