fgetpos() - I/O Function
How is "fgetpos()" used in C++?
How to get current file position?
Explanation
fgetpos() is an I/O function which is used to get the current value of the file position indicator in the object pointed by the position. The function return a zero value on success, a non-zero value if an error occurs.
Syntax:
int fgetpos( FILE * stream, fpos_t *position );
Example :
#include <stdio.h> int main () { FILE * str= fopen ("fgetposeg.txt","r"); int a; fpos_t pos; a = fgetc (str); printf ("First character in the file is %c\n",a); fgetpos (str,&pos); fclose (str); return 0; } |
Result :
First character in the file is j
In the above example the "fgetpos()" is used to find the first character from the text file. This gives the current file position.