On this page
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
- Avoid
fseek+ftellon >2 GiB files (longis 32-bit on Windows): Usefseeko/ftelloon POSIX orfgetpos/fsetpos.
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
- tuts/c/stdlib/stdio/ftell Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fwrite Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib
- tuts/c/stdlib/stdio_and_file_io Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdio/fclose shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/feof shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/ferror shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fflush shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fgets shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fopen shared tags: #c, #prog, #stdio, #stdlib, #tier