fseek, rewind, ftell
Purpose
Repositions the file pointer of a stream.
Library
Standard I/O Library (libc.a)
Syntax
#include <stdio.h>
int fseek (stream, offset, whence) void rewind (stream)
FILE *stream; FILE *stream;
long offset;
int whence; long ftell (stream)
FILE *stream;
Description
The fseek subroutine sets the position of the next input
or output operation on the I/O stream specified by the
stream parameter. The position of the next operation is
determined by the offset parameter, which can be either
positive or negative.
The fseek subroutine sets the file pointer associated
with the specified stream as follows:
o If the whence parameter is 0, the pointer is set to
the value of the offset parameter.
o If the whence parameter is 1, the pointer is set to
its current location plus the value of the offset
parameter.
o If the whence parameter is 2, the pointer is set to
the size of the file plus the value of the offset
parameter.
The fseek subroutine fails if attempted on a file that
has not been opened using fopen. In particular, fseek
cannot be used on a terminal, or on a file opened with
popen.
Upon successful completion, fseek returns a value of 0.
If fseek fails, a nonzero value is returned.
The rewind subroutine is equivalent to fseek (stream,
(long) 0, 0), except that it does not return a value.
The fseek and rewind subroutines undo any effects of the
ungetc subroutine.
After an fseek or a rewind, the next operation on a file
opened for update can be either input or output.
The ftell subroutine returns the offset of the current
byte relative to the beginning of the file associated
with the named stream.
Related Information
In this book: "lseek," "fopen, freopen, fdopen," and
"standard i/o library."