function
<cstdio>

fsetpos

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.

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 zero.
On failure, a non-zero value is returned and errno is set to a system-specific positive value.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* 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