int fsetpos ( FILE * stream, const fpos_t * pos );
Set position indicator of stream
Restores the current position in the stream to pos.
The internal file position indicator associated with stream is set to the position represented by pos, which is a pointer to an fpos_t object whose value shall have been previously obtained by a call to fgetpos.
The end-of-file internal indicator of the stream is cleared after a successful call to this function, and all effects from previous calls to ungetc on this stream are dropped.
On streams open for update (read+write), a call to fsetpos allows to switch between reading and writing.
A similar function, fseek, can be used to set arbitrary positions on streams open in binary mode.
- Pointer to a FILE object that identifies the stream.
- Pointer to a fpos_t object containing a position previously obtained with fgetpos.
If successful, the function returns zero.
On failure, a non-zero value is returned and errno is set to a system-specific positive value.
/* fsetpos example */
int main ()
FILE * pFile;
pFile = fopen ("myfile.txt","w");
fgetpos (pFile, &position);
fputs ("That is a sample",pFile);
fsetpos (pFile, &position);
After this code is successfully executed, a file called myfile.txt will contain:
- Get current position in stream (function)
- Reposition stream position indicator (function)
- Set position of stream to the beginning (function)