What is fseek() in C?
The C library function fseek() sets the file position of the stream to a given offset. The pointer associated with the file is moved to that offset.
Syntax
The basic syntax of the function is:
whence defines the point with respect to where the file pointer needs to be moved. It is specified by one of the following constants:
- SEEK_END: End of the file.
- SEEK_SET: Beginning of the file.
- SEEK_CUR: Current position of the file pointer.
Code
The following code opens a text file and moves the pointer to the end of the file using the SEEK_END argument. It then moves the pointer three places ahead of the start of the file, using the SEEK_SET argument, and prints the remaining characters in the file.
main.c
file.txt
Hello World
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved