int  fsetpos ( FILE * stream , const   fpos_t * position );

Reposition file pointer to a saved location.
  Sets the file pointer associated with stream to a new position. The position parameter is a value previously obtained by a call to fgetpos.
  After a call to this function, the End-Of-File indicator of the stream is cleared and any effect of a previous call to ungetc is undone.
  The next operation with the stream after a call to fsetpos can be either for input or output.


Pointer to an open file.
Position value obtained from a previous call to fgetpos that indicates the position of the file pointer at that moment.

Return Value.
  If successful the function returns 0.
  Otherwise it returns nonzero and sets the global variable errno to a non-zero value.

  Defined in ANSI-C.


/* fsetpos example */
#include <stdio.h>

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 executed, a file called myfile.txt will be created and will contain the sentence
This is a sample

See also.
  fopen, fgetpos, fseek ftell, frewind

© The C++ Resources Network, 2000