| cplusplus.com > reference > cstdio > fgetpos | 
| 
fgetpos
 <stdio.h>  | 
| cplusplus.com | 
 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.
Parameters.
 Return Value.
 
0 value indicates success.
 
non-zero value indicates error.
 Example.
/* fgetpos example */
#include <stdio.h>
int main ()
{
   FILE * pFile;
   char c;
   int n;
   fpos_t pos;
   pFile = fopen ("myfile.txt","r");
   if (pFile==NULL) perror ("Error opening file");
   else
   {
     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;
}
Output:
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