Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamescanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : rewind

voidrewind(FILE * stream) ;

Return Type : void

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

1st Parameter Type : FILE *

Pointer to FILE structure for file operations

1st Parameter

Pointer to the FILE stream to be reset to the beginning.
FILE pointer parameter must be:
Valid (not NULL);
From successful fopen() call;
Not previously closed;
File must be seekable (not all streams are);

Read more about parameters of rewind in parameters section
The rewindfunction in C language sets the file position to the beginning of the file stream.
rewind is a stream positioning function used to reset a file stream back to its beginning, commonly used when multiple passes through a file are needed or to restart reading/writing from the start. What makes it special is its automatic clearing of both error and EOF indicators while repositioning, making it simpler to use than fseek for returning to file start. The function works as part of the file positioning family with fseek and ftell, and affects all subsequent I/O operations like fread, fwrite, fprintf, fscanf that depend on the file position indicator.

To Summarize the Workflow:
  1. 1.
    Takes FILE pointer as single parameter
  2. 2.
    Sets file position indicator to beginning of file
  3. 3.
    Clears the error indicator
  4. 4.
    Clears the EOF indicator
  5. 5.
    No return value (void function)
  6. 6.
    Clears all buffers in the process


rewind(FILE *stream)

Clear error indicator

Clear EOF indicator

Set position to beginning

Return void




Read more about return type and value ofrewind function in return section.
The rewindfunction takes 1 parameter:
  • FILE * `stream`: Pointer to the FILE stream to be reset to the beginning.
    FILE pointer parameter must be:
    Valid (not NULL);
    From successful fopen() call;
    Not previously closed;
    File must be seekable (not all streams are);
Key effects on parameter stream:
Position indicator reset to beginning;
Error indicator cleared;
EOF indicator cleared;
Any pushed-back character (ungetc) is lost;
Buffered data is flushed;

The rewind function return value :
  • This function does not return a value
    Though rewind() is a void function , there are important return-related considerations:
    ● No direct way to detect failure
    ● Must use other functions to check if rewind succeeded:
    ferror() to check new errors
    ftell() to verify position is 0
    fgetpos() to check position

    Important: The fact that it's void means errors must be detected indirectly, which makes it different from similar functions like fseek that return error status directly

Output

This example writes a string to a file, uses rewind to move the file position indicator back to the beginning, and then reads and prints the content.