Table of Content

fgetpos >> gets the current file pointer position >> Stdio.h function

fgetpos :

  1. fgetpos gets the current file pointer position.
  2. fgetpos stores the position of the file pointer associated with the given stream in the location *pos
  3. The exact value is irrelevant.

Syntax :

int fgetpos(FILE *stream, fpos_t *pos);

Live Example :

char s[100];
fpos_t pos;

fgets(s, sizeof(s), fp); // read a line from the file

fgetpos(fp, &pos); // save the position

fgets(s, sizeof(s), fp); // read another line from the file

fsetpos(fp, &pos); // now restore the position to where we saved

Return Value :

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