Changes the file position indicator of a stream.
#include <stdio.h> int fseek ( FILE *fp, long int offset, int whence);
(IN) Points to the file.
(IN) Specifies the file position to seek. For a text stream, the offset must be either zero or the value returned by an earlier successful call ftell.
(IN) Specifies the relative file position and uses one of the following flags:
If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:
The fseek function changes the read/write position of the file specified by fp. This position defines the character to be read or written on the next I/O operation on the file. The fp parameter is a file pointer returned by fopen or freopen. The offset parameter is the position to seek, relative to one of three positions specified by the whence parameter.
The fseek function clears the end-of-file indicator and undoes any effects of the ungetc function on the same file.
When operating on a text file, you can only set the whence parameter to SEEK_SET and you can only set the offset parameter to 0 or a value obtained from ftell. Any other combinations have indeterminate results. You can restore a position by using the value returned by ftell in a subsequent call to fseek with the whence parameter set to SEEK_SET.