Syntax
#include <stdio.h> int fgetpos(FILE *stream, fpos_t *pos);Description
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.
fgetpos returns 0 if successful. On error, fgetpos returns nonzero and sets errno to a nonzero value.
This example opens the file myfile.dat 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("myfile.dat", "rb"); /* The value returned by fgetpos can be used by fsetpos */ /* to set the file pointer if 'retcode' is 0 */ if ( 0 == (retcode = fgetpos(stream, &pos)) ) printf("Current position of file pointer found.\n"); fclose(stream); return 0; /**************************************************************************** If myfile.dat exists, the output should be: Current position of file pointer found. ****************************************************************************/ }Related Information