On this page
  1. fseek
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

fseek

Prev: fwrite | Up: stdio.h | Next: ftell
Rel: stdio.h, stdio.h & File I/O Guide
Ref: cppreference — fseek
Tags: #public #prog #c #stdlib #stdio #tier/standard


Include

#include <stdio.h>

Signature & Overview

int fseek(FILE *stream, long offset, int origin);

Moves the file position indicator relative to SEEK_SET, SEEK_CUR, or SEEK_END.

Notes & Pitfalls

Example

#include <assert.h>
#include <stdio.h>

int main(void) {
    FILE *f = tmpfile();
    fwrite("hello", 1, 5, f);
    assert(fseek(f, 0, SEEK_END) == 0 && ftell(f) == 5);
    fclose(f);
}

Linked from

Related notes