Table of Content

fsetpos function >> sets file pointer of stream to a new position >> C Programming



fgetpos :

  1. Header File  :  Stdio.h
  2. fsetpos sets [positions] the file pointer of a stream
  3. fsetpos sets the file pointer associated with stream to a new position
  4. The new position is the value obtained by a previous call to fgetpos on that stream.
  5. Fsetpos also clears the end-of-file indicator on the file *stream and undoes any effects of ungetc on that file.
  6. fgetpos stores the position of the file pointer associated with the given stream in the location *pos
  7. The exact value is irrelevant.

Syntax :

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

Live Example :

int main ()
{
FILE * fp;
fpos_t position;

fp = fopen ("file1.txt","w");

fgetpos (fp, &position); // Store New Position
fputs ("What an Idea",fp);

fsetpos (fp, &position); // Set Current Position to New Position
fputs ("This",fp);

fclose (fp);
return 0;
}

Return Value :

  1. On success : Return 0
  2. On Error : Returns a non-zero value