[Previous]
[Contents]
[Next]

fgetpos()

store the current position of a file

Synopsis:

#include <stdio.h>
int fgetpos( FILE *fp, fpos_t *pos );

Description:

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.

Returns:

0
Success
Nonzero
An error occurred. errno is set to indicate the error.

Examples:

#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 );
    }
  }

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, fopen(), fseek(), fsetpos(), ftell()


[Previous]
[Contents]
[Next]