store the current position of a file
#include <stdio.h> int fgetpos( FILE *fp, fpos_t *pos );
The fgetpos() function stores the current position of the file fp in the object pointed to by pos. The value stored can be used by the fsetpos() function for repositioning the file to its position at the time of the call to the fgetpos() function.
#include <stdio.h> void main() { FILE *fp; fpos_t position; char buffer[80]; fp = fopen( "file", "r" ); if( fp != NULL ) { fgetpos( fp, &position ); /* get position */ fgets( buffer, 80, fp ); /* read record */ fsetpos( fp, &position ); /* set position */ fgets( buffer, 80, fp ); /* read same record */ fclose( fp ); } }
ANSI
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
errno, fopen(), fseek(), fsetpos(), ftell()