Three functions are available for setting and determining the position of the file pointer for a given file.
Return the position of the file pointer as the number of characters from the beginning of the file specified by file descriptor fid.
See also: fseek, frewind, feof, fopen.
Set the file pointer to the location offset within the file fid.
The pointer is positioned offset characters from the origin,
which may be one of the predefined variables
SEEK_SET (beginning), or
SEEK_END (end of
file) or strings
origin is omitted,
SEEK_SET is assumed. offset may
be positive, negative, or zero but not all combinations of origin and
offset can be realized.
fseek returns 0 on success and -1 on error.
See also: fskipl, frewind, ftell, fopen.
Return the numerical value to pass to
fseek to perform one of the
Position file relative to the beginning.
Position file relative to the current position.
Position file relative to the end.
See also: fseek.
Move the file pointer to the beginning of the file specified by file descriptor fid.
frewind returns 0 for success, and -1 if an error is encountered. It
is equivalent to
fseek (fid, 0, SEEK_SET).
See also: fseek, ftell, fopen.
The following example stores the current file position in the variable
marker, moves the pointer to the beginning of the file, reads
four characters, and then returns to the original position.
marker = ftell (myfile); frewind (myfile); fourch = fgets (myfile, 4); fseek (myfile, marker, SEEK_SET);