FSEEK - reposition I/O stream.

(ANSI Standard)


#include <stdio.h>
ret = fseek( f, offset, from );


FILE *f;
points to the file on which I/O is to be repositioned.
long offset;
is an integer giving the number of bytes to move forward or backward in the file. This may be positive or negative, provided it makes sense (e.g. it does not make sense to have a negative offset if you are starting at the beginning of the file).
int from;
is one of the manifests SEEK_SET, SEEK_CUR, or SEEK_END (see below).
int ret;
is non-zero if the seek operation was invalid (e.g. on a file not opened with a "b" option); otherwise, the return value is zero.


"fseek" repositions the I/O stream of the file "f". If "f" is a binary stream:

If "f" is a sequential stream:

"fseek" undoes any effects of "ungetc"; see "expl c lib ungetc".

If you have a file opened for update and you want to switch from reading to writing or vice versa, you must do an "fseek" (or "rewind" or some similar operation).


You cannot perform "fseek" operations on terminals or on SYSOUT.

"fseek" does not work on input streams which are concatenations of several input files.

We recommend that you use the ANSI standard functions "fsetpos" and "fgetpos" instead of "fseek" and "ftell". The reason is that "fseek" and "ftell" only use a long integer (36 bits) to represent a position in a file; this is not adequate to deal with all the positions in a large GCOS8 file. On the other hand, "fgetpos" and "fsetpos" use a larger information structure to represent file positions and can deal with any size file.

See Also:

expl nsc lib ftell

expl nsc lib fopen

expl nsc lib fsetpos

expl nsc lib fgetpos

Copyright © 1996, Thinkage Ltd.