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

Get position in a stream.
  Gets the value of the position indicator of the given stream and stores it in the location pointed by position in a format that is only intended for use as a paremeter in further calls to fsetpos.
  If you want to get the current position of a stream for any other use than as a parameter for fsetpos you should call to ftell function.


pointer to an open file.
pointer to a fpos_t object where the position will be stored.
fpos_t is defined in stdio.h as long and it is only used with fgetpos and fsetpos functions.

Return Value.
  0 value indicates success.
  non-zero value indicates error.


/* fgetpos example */
#include <stdio.h>
   FILE * pFile;
   char c;
   int n;
   fpos_t pos;

   pFile = fopen ("myfile.txt","r");
   if (pFile==NULL) perror ("Error opening file");
     c = fgetc (pFile);
     printf ("1st character is %c\n",c);
     fgetpos (pFile,&pos);
     for (n=0;n<3;n++)
        fsetpos (pFile,&pos);
        c = fgetc (pFile);
        printf ("2nd character is %c\n",c);
     fclose (pFile);
   return 0;
1st character is A
2nd character is B
2nd character is B
2nd character is B
This example opens myfile.txt. It reads the first character once and then it reads 3 times the same second character.

See also.
  fsetpos, ftell, fseek

© The C++ Resources Network, 2000