Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : fseek

intfseek(FILE * stream,long offset,int whence) ;

Return Type : int

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

1st Parameter Type : FILE *

Pointer to FILE structure for file operations

1st Parameter

Pointer to the file stream for which the file position is to be changed

2nd Parameter Type : long

Large integer type (4 or 8 bytes platform dependent)

2nd Parameter

The number of bytes to move the file position relative to the `whence` parameter

3rd Parameter Type : int

Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)

3rd Parameter

Specifies the reference point for `offset`. Possible values are `SEEK_SET`, `SEEK_CUR`, or `SEEK_END`

Read more about parameters of fseek in parameters section
The fseekfunction in C language Sets the file position of the stream to the given offset.
fseek is used for navigating within files by setting the file position indicator, essential for random access operations and non-sequential file processing. What makes it special is its flexibility with three different positioning modes (from start, from current position, or from end) and its ability to work with both binary and text files (though behavior may differ). The function is part of the file positioning family along with ftell for tracking position, rewind for returning to start, and it affects all I/O operations (like fread, fwrite, fprintf, fscanf) that depend on file position. Any positioning operation clears stream status (EOF indicator) and flushes any buffered I/O operations.

To Summarize the Workflow:
  1. 1.
    Takes three parameters: stream, offset, and reference point (whence)
  2. 2.
    Moves file position indicator to specified location
  3. 3.
    Clears EOF indicator
  4. 4.
    Returns 0 on successful repositioning
  5. 5.
    Returns non-zero and sets error indicator on failure
  6. 6.
    Discards any characters pushed back by ungetc

Yes

No

Success

Invalid

Success

Failure

fseek(FILE *stream, long offset, int whence)

Valid whence?

Position computation

Set position

Return 0 Position set

Return non-zero Set error indicator




Read more about return type and value offseek function in return section.
The fseekfunction takes 3 parameters:
  • FILE * `stream`: Pointer to the file stream for which the file position is to be changed
  • long `offset`: The number of bytes to move the file position relative to the `whence` parameter
  • int `whence`: Specifies the reference point for `offset`. Possible values are `SEEK_SET`, `SEEK_CUR`, or `SEEK_END`
The fseek function return value :
  • Returns 0 if successful, or non-zero if an error occurred

Output

This example demonstrates the basic usage of `fseek`. It opens a file, seeks to the 10th byte from the beginning of the file, and then reads and prints the character at that position.