7.19.9.2 The fseek function
Synopsis
1 #include <stdio.h>
int fseek(FILE *stream, long int offset, int whence);
Description
2 The fseek function sets the file position indicator for the stream pointed to by stream.
If a read or write error occurs, the error indicator for the stream is set and fseek fails.
3 Forabinary stream, the newposition, measured in characters from the beginning of the
file, is obtained by adding offset to the position specified by whence.The specified
position is the beginning of the file if whence is SEEK_SET,the current value of the file
position indicator if SEEK_CUR,orend-of-file if SEEK_END.Abinary stream need not
meaningfully support fseek calls with a whence value of SEEK_END.
4 Foratextstream, either offset shall be zero, or offset shall be a value returned by
an earlier successful call to the ftell function on a stream associated with the same file
and whence shall be SEEK_SET.
5 After determining the newposition, a successful call to the fseek function undoes any
effects of the ungetc function on the stream, clears the end-of-file indicator for the
stream, and then establishes the newposition. After asuccessful fseek call, the next
operation on an update stream may be either input or output.
Returns
6 The fseek function returns nonzero only for a request that cannot be satisfied.
Partager