Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : clearerr

voidclearerr(FILE * stream) ;

Return Type : void

Type that indicates no return value
Read about return values of clearerr function .

1st Parameter Type : FILE *

Pointer to FILE structure for file operations

1st Parameter

Pointer to a file stream that error and end-of-file indicators are to be cleared for.

Read more about parameters of clearerr in parameters section
The clearerrfunction in C language clears the error and end-of-file indicators for a given stream.
clearerr is primarily used in error recovery scenarios when working with file streams in C language. It works as part of an error handling team with ferror and feof, typically after a failed I/O operation (like fread, fwrite, fgets, getc,after an error using ferror or end-of-file using feof is detected.
It is the only function that can clear both indicators (error and end-of-file) at once.
No return value since it just performs the clearing operation,so the indicators should be checked again after clearerr runs in order to make sure it's run was successful.

To Summarize the Workflow:
  1. 1.
    Function receives a pointer to a FILE stream (clearerr(FILE *stream))
  2. 2.
    Clears the error indicator flag in the stream
  3. 3.
    Clears the EOF indicator flag in the stream
  4. 4.
    Returns void (no return value)
  5. 5.
    Used to reset stream state after error handling
  6. 6.
    Allows stream operations to continue after error conditions


clearerr(FILE *stream)

Clear error indicator

Clear EOF indicator

Return void




Read more about return type and value ofclearerr function in return section.
The clearerrfunction takes 1 parameter:
  • FILE * `stream`: Pointer to a file stream that error and end-of-file indicators are to be cleared for.
The clearerr function return value :
  • This function does not return a value
    Since clearerr returns void, there's no way to verify if the clearing operation was successful without additional operation
  • You can't check its return value to confirm the indicators were cleared
  • To verify that, you would need to call ferror and/or feof

Output

This example demonstrates how to use `clearerr` to clear the end-of-file indicator after reading a file to its end. It shows the state of the EOF indicator before and after calling clearerr.