int fsetpos ( FILE * stream, const fpos_t * pos ); |
<cstdio> |
Set position indicator of stream
Changes the internal file position indicator associated with stream to a new position. The position parameter is a pointer to an fpos_t object whose value shall have been previously obtained with a call to fgetpos.
The End-of-File internal indicator of the stream is cleared after a call to this function, and all effects from previous calls to ungetc are dropped.
On streams open for update (read+write), a call to fsetpos allows to switch between reading and writing.
Parameters
- stream
- Pointer to a FILE object that identifies the stream.
- position
- Pointer to a fpos_t object containing a position previously obtained with fgetpos.
Return Value
If successful, the function returns a zero value.
Otherwise, it returns a nonzero value and sets the global variable
errno to a positive value, which can be interpreted with
perror.
Example
/* fsetpos example */
#include <stdio.h>
int main ()
{
FILE * pFile;
fpos_t position;
pFile = fopen ("myfile.txt","w");
fgetpos (pFile, &position);
fputs ("That is a sample",pFile);
fsetpos (pFile, &position);
fputs ("This",pFile);
fclose (pFile);
return 0;
}
|
After this code is successfully executed, a file called myfile.txt will contain:
This is a sample
See also
fgetpos | Get current position in stream (function) |
fseek | Reposition stream position indicator (function) |
rewind | Set position indicator to the beginning (function) |