Everything

fseek


Shifts the current read/write position in a stream input/output file.

[Format]

#include <stdio.h>

long fseek (FILE *fp, long offset, long type);

[Parameters]

fp File pointer

offset Offset from position specified by type of offset

type Type of offset

[Return values]

Normal: 0

Abnormal: Nonzero

[Remarks]

The fseek function shifts the current read/write position in the stream input/output file indicated by file pointer fp by offset bytes from the position specified by type (the type of offset).

The types of offset are shown in Table 7.14.

The fseek function normally returns zero, but returns nonzero in response to an invalid request.

Table 7.14

Types of Offset

Offset Type

Meaning

SEEK_SET

Shifts to a position which is located offset bytes away from the beginning of the file. The value specified by offset must be zero or positive.

SEEK_CUR

Shifts to a position which is located offset bytes away from the current position in the file. The shift is toward the end of the file if the value specified by offset is positive, and toward the beginning of the file if negative.

SEEK_END

Shifts to a position which is located offset bytes forward from end-of-file. The value specified by offset must be zero or negative.

 

For a text file, the type of offset must be SEEK_SET and offset must be zero or the value returned by the ftell function for that file. Note also that calling the fseek function cancels the effect of the ungetc function.