### fgetpos -- Get File Position

Format

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

Language Level: ANSI, XPG4
fgetpos stores the current position of the file pointer associated with stream into the object pointed to by pos. The value pointed to by pos can be used later in a call to fsetpos to reposition the stream.

Note: For buffered text streams, fgetpos returns an incorrect file position if the file contains new-line characters instead of carriage-return line-feed combinations. Your file would only contain new-line characters if you previously used it as a binary stream. To avoid this problem, either continue to process the file as a binary stream, or use unbuffered I/O operations.

Return Value
fgetpos returns 0 if successful. On error, fgetpos returns nonzero and sets errno to a nonzero value.

Example
This example opens the file "myfile.dat" for reading and stores the current file pointer position into the variable pos.

    #include <stdio.h>

    #define FILENAME "myfile.dat"

    FILE *stream;

    int main(void)
    {
       int retcode;
       fpos_t pos;

       stream = fopen("FILENAME", "rb");

       /* The value returned by fgetpos can be used by fsetpos */
       /* to set the file pointer if 'retcode' is 0            */

       if ((retcode = fgetpos(stream, &pos)) == 0)
          printf("Current position of file pointer found\n");
       fclose(stream);

       /*********************************************************
          If FILENAME exists, the output should be:

          Current position of file pointer found.
       *********************************************************/
    }

fseek -- Reposition File Position
fsetpos -- Set File Position
ftell -- Get Current Position
<stdio.h>