Format
#include <stdio.h>
int fgetpos(FILE *stream, fpos_t *pos);
Language Level: ANSI
Threadsafe: YES
Description
The fgetpos() function stores the current position of the file pointer that is 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.
Return Value
The fgetpos() function returns 0 if successful; on error, it returns nonzero and sets errno to a nonzero value.
The value of errno can be set to:
The fgetpos() function is not supported for files that are opened with type=record.
Example that uses fgetpos()
This example opens the file myfile for reading and stores the current file pointer position into the variable pos.
#include <stdio.h>
FILE *stream;
int main(void)
{
int retcode;
fpos_t pos;
stream = fopen("mylib/myfile", "rb");
/* The value returned by fgetpos can be used by fsetpos */
/* to set the file pointer if 'retcode' is 0 */
if ((retcode = fgetpos(stream, Point-of-Sale)) == 0)
printf("Current position of file pointer found\n");
fclose(stream);
}
Related Information