fgetpos
int fgetpos (FILE * stream , fpos_t * position); | 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> 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:
See also.
fsetpos,
ftell,
fseek