Names specified here
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_CUR File-position origin: current position M <stdio.h> C89 C90 C95 C99 C11
SEEK_END File-position origin: end M <stdio.h> C89 C90 C95 C99 C11
SEEK_SET 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:

Origins for fseek
Value of whence Origin for offset
SEEK_SET start of the stream
SEEK_CUR current position
SEEK_END 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.


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2022-06-17T21:43:05.000+0000