liveBook · Manning

Fseek

As explained in Modern C, Third Edition

fseek is a C standard-library function that changes a stream's file position relative to a specified reference position.

fseek changes a file stream’s current position using an offset and a reference specified by whence. SEEK_SET measures from the file start; SEEK_CUR measures from the position before the call. section 14.6

 size_t fread(void* restrict ptr, size_t size, size_t nmemb,
              FILE* restrict stream);
 size_t fwrite(void const*restrict ptr, size_t size, size_t nmemb,
               FILE* restrict stream);
 int fseek(FILE* stream, long int offset, int whence);
 long int ftell(FILE* stream);

The declaration shows fseek’s FILE stream, long offset, and whence arguments alongside fread, fwrite, and ftell. section 14.6

Use fseek with the binary-stream position model:

  • Combine fseek with ftell to reposition and inspect a stream’s byte position. section 14.6
  • Move forward or backward through a file, then read or write bytes at the resulting position. section 14.6
  • Open streams used with binary I/O in binary mode for portability. section 14.6

How Modern C, Third Edition covers it

How deep it goes
Explains the function signature, reference positions, and forward or backward movement, but does not show a complete fseek call.
Examples
Uses byte-wise movement through a file and internal object representations as applications of binary positioning.
What it assumes
Assumes familiarity with C streams and teaches file position through fread, fwrite, and ftell relationships.
What you can do after
Operate on binary file positions using fseek with SEEK_SET or SEEK_CUR and coordinate subsequent byte I/O.
How it connects
Connects fseek with ftell, fread, fwrite, binary streams, and file-position tracking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.