Full prototype:

int fseek(FILE*, long int, int);  

Purpose and Notes:

Sets the current file position of the stream associated with the first argument's FILE* using the starting position of the stream specified by the third argument and an offset specified by the second argument. The third argument can accept one of the three macros defined in the <stdio.h> header being either SEEK_SET which refers to the beginning of the file, SEEK_CUR which refers to the current position set for the stream, and SEEK_END which is the end of the file.

For binary files using an offset other than 0 while the third argument specified is SEEK_END is undefined, otherwise it takes a position as the third argument and then uses the second argument as an offset to indicate how many bytes away from the third argument position you want to set the new file position.

If the file is a text stream then the only standard defined way to use it is one of the following ways:
  1. The second argument must be 0.
  2. The second argument is value from a previous call to ftell() and the third argument is SEEK_SET.

For portablity fsetpos and fgetpos are recommended, but sometimes more irritating to use. This is because ftell() and fseek() are defined to work with long int for the position of the stream, but if you want to read from a file larger than that which can be stored in the implementations long int, then POSIX ftello() and fseeko() or fgetpos() and fsetpos() need to be used. fgetpos() and fsetpos() use an implementation definded type that can potentially be greater than type long used by fseek() and ftell().


int- Zero on success and non-zero otherwise.

Argument 1:

FILE*- A stream associated with the FILE* from which you want to move the current location in the file.

Argument 2:

long int- The offset from the third argument from which you want to set the current location.

Argument 3:

int- The position from which you want the offset added with to determine the new location to be set for the stream.

Example 1