Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : feof

intfeof(FILE * stream) ;

Return Type : int

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

1st Parameter Type : FILE *

Pointer to FILE structure for file operations

1st Parameter

Pointer to the file stream to check for the end-of-file condition

Read more about parameters of feof in parameters section
The feoffunction in C language checks if the end of the file has been reached.
The feof function tests the end-of-file indicator for the given stream. The end-of-file indicator is set by previous operations on the stream that reached the end of the file. It's important to note that feof does not detect the end-of-file by itself; it only reports whether the indicator has been set by a previous operation.This flag is typically set when a file operation attempts to read past the end of the file.
feof is often used in loops to detect the end of a file when reading its contents. However, it is generally better to check the result of the actual read operation (like fgetc, fgets, fread,getc etc.) for EOF, as relying solely on feof can lead to subtle bugs.
The feoffunction takes 1 parameter:
  • FILE * `stream`: Pointer to the file stream to check for the end-of-file condition
Checks whether the end-of-file (EOF) indicator associated with the specified file stream is set. Returns a nonzero value if EOF is reached, otherwise returns 0.
The feof function return value :
  • Returns a non-zero value if the end-of-file indicator is set for the stream, otherwise returns zero
    CASE 1: feof() returns 1 (YES path)

    This can happen in TWO distinct situations:
    Genuine EOF:
    A previous read operation reached the end of file
    Example: getc() tried to read past the last byte
    Normal condition, indicates successful read until the end
    Read Operation Failed:
    Some I/O error occurred during reading
    Could be: permissions, disk error, corrupted file, etc
  • Abnormal condition, indicates an error state
    CASE 2: feof() returns 0 (NO path)
    This can happen in TWO distinct situations:
    Normal Reading State:
    There's more data available to read
    File pointer is somewhere before EOF
    Common during normal file processing
    Fresh File:
    File just opened
    No read operations attempted yet
    EOF indicator not set because nothing has been read
    So in total we have 4 distinct scenarios leading to 2 possible return values

feof(FILE *stream) EOF indicator set? Yes No Return 1 Return 0 CASE 1.1: End of file reached CASE 1.2: Read operation failed CASE 2.1: More data available CASE 2.2: File newly opened getc() read past last byte (Normal condition) I/O error occurred: permissions/disk/ corruption

Output

This example demonstrates the basic usage of `feof`. It reads a file character by character until EOF is reached, then uses feof to confirm that the end of the file was reached.