Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
fgetpos() |
Get stream position | (·) | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
fpos_t |
Stream-position type | T | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
fseek() |
Set stream position | (·) | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
fsetpos() |
Set stream position | (·) | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
ftell() |
Get stream position | (·) | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
rewind() |
Reset stream position | (·) | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
SEEK_ |
File-position origin: current position | M | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
SEEK_ |
File-position origin: end | M | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
SEEK_ |
File-position origin: beginning | M | <stdio.h> |
C89 | C90 | C95 | C99 | C11 |
Every stream has
a stream position, which advances automatically
when you read from or write to the stream. Stream position is
represented either as a simple long
, or as an
fpos_t
,
defined in <stdio.h>
.
fpos_t
has two advantages over long
. First, it
can have a greater range than long
. Second,
it retains multibyte state when
operating on wide-oriented streams, so you can record and
restore not only position, but that conversion state too.
Five functions exist to manipulate the stream position:
#include <stdio.h>
long ftell(FILE *stream);
int fseek(FILE *stream, long offset, int whence);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, const fpos_t *pos);
void rewind(FILE *stream);
ftell
and fgetpos
get the current stream position. fseek
and fsetpos
set the current position. fseek
takes an addition argument whence
,
which has the following meanings:
Value of whence |
Origin for offset |
---|---|
SEEK_ |
start of the stream |
SEEK_ |
current position |
SEEK_ |
end of the stream |
rewind
has two effects. It sets the stream position to the start of
the stream, and clears the error and
end-of-file indicators.