Export (0) Print
Expand All
div
Expand Minimize
1 out of 1 rated this helpful - Rate this topic

fgetpos

Gets a stream's file-position indicator.

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

Parameters

stream
Target stream.
pos
Position-indicator storage.

Return Value

If successful, fgetpos returns 0. On failure, it returns a nonzero value and sets errno to one of the following manifest constants (defined in STDIO.H): EBADF, which means the specified stream is not a valid file pointer or is not accessible, or EINVAL, which means the stream value is invalid.

See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, return codes.

Remarks

The fgetpos function gets the current value of the stream argument's file-position indicator and stores it in the object pointed to by pos. The fsetpos function can later use information stored in pos to reset the stream argument's pointer to its position at the time fgetpos was called. The pos value is stored in an internal format and is intended for use only by fgetpos and fsetpos.

Requirements

Function Required header Compatibility
fgetpos <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_fgetpos.c
/* This program opens a file and reads
 * bytes at several different locations.
 */

#include <stdio.h>

int main( void )
{
   FILE   *stream;
   fpos_t pos;
   char   buffer[20];

   if( (stream = fopen( "crt_fgetpos.txt", "rb" )) == NULL )
      printf( "Trouble opening file\n" );
   else
   {
      /* Read some data and then check the position. */
      fread( buffer, sizeof( char ), 5, stream );
      if( fgetpos( stream, &pos ) != 0 )
         perror( "fgetpos error" );
      else
      {
         fread( buffer, sizeof( char ), 10, stream );
         printf( "10 bytes at byte %I64d: %.10s\n", pos, buffer );
      }

   /* Set a new position and read more data */
   pos = 14;
   if( fsetpos( stream, &pos ) != 0 )
      perror( "fsetpos error" );

   fread( buffer, sizeof( char ), 10, stream );
   printf( "10 bytes at byte %I64d: %.10s\n", pos, buffer );
   fclose( stream );
   }
}

Input: crt_fgetpos.txt

This is the input for crt_fgetpos.

Output

10 bytes at byte 5: is the inp
10 bytes at byte 14: put for cr

See Also

Stream I/O Routines | fsetpos | Run-Time Routines and .NET Framework Equivalents

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.