fgetpos (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Gets a stream's file-position indicator.

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

Parameters

  • stream
    Target stream.
  • pos
    Position-indicator storage.

Return Values

If successful, fgetpos returns 0.

On failure, it returns a nonzero value.

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.

Example

/* FGETPOS.C: This program opens a file and reads
 * bytes at several different locations.
 * Place this code in a file called FGETPOS.C and then 
 * put the file in your project directory.
 */

#include <stdio.h>

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

   if( (stream = fopen( "fgetpos.c", "rb" )) == NULL )
      printf( "Trouble opening file\n" );
   else
   {
      /* Read some data and then check the position. */
      fread( buffer, sizeof( char ), 10, stream );
      if( fgetpos( stream, &pos ) != 0 )
         printf( "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 = 140;
   if( fsetpos( stream, &pos ) != 0 )
      printf( "fsetpos error" );

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

Output

10 bytes at byte 10: .C: This p
10 bytes at byte 140: .C and the

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also

fsetpos

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.