Function fseek

Top 

Declaration:

int fseek(unsigned long stream, long offset, int fromwhere);

Description

Repositions a file pointer on a stream.

fseek sets the file pointer associated with stream to a new position that is offset bytes from the file location given by fromwhereoffset should be 0 or the value returned by ftellfromwhere must be one of the values 0. 1, or 2, which represent three symbolic constants (defined in system.h) as follows:

Constant     fromwhere  File location

----------------------------------------------------

SEEK_SET     0          Beginning of the file

SEEK_CUR     1          Current file pointer position

SEEK_END     2          End-of-file

fseek discards any character pushed back. fseek is used with stream I/O; for file handle I/O, use lseek. The next operation on the update file after fseek can be either input or output.

Returned Value

fseek will return 0, if the pointer is successfully moved, and nonzero on failure. fseek may return 0 indicating that the pointer has been moved successfully, when in fact it has not been. This is because DOS, which actually resets the pointer, does not verify the setting. fseek returns an error code only on an unopened file or device. In the event of an error return, the errno global variable is set to one of the following values:

EBADF        Bad file pointer

EINVAL       Invalid argument

ESPIPE       Illegal seek on device