function
<cstdio>
fgetposint fgetpos ( FILE * stream, fpos_t * pos );
Get current position in stream
Retrieves the current position in the stream.The function fills the fpos_t object pointed by pos with the information needed from the stream's position indicator to restore the stream to its current position (and multibyte state, if wide-oriented) with a call to fsetpos.
The ftell function can be used to retrieve the current position in the stream as an integer value.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* fgetpos example */
#include <stdio.h>
int main ()
{
FILE * pFile;
int c;
int n;
fpos_t pos;
pFile = fopen ("myfile.txt","r");
if (pFile==NULL) perror ("Error opening file");
else
{
c = fgetc (pFile);
printf ("1st character is %c\n",c);
fgetpos (pFile,&pos);
for (n=0;n<3;n++)
{
fsetpos (pFile,&pos);
c = fgetc (pFile);
printf ("2nd character is %c\n",c);
}
fclose (pFile);
}
return 0;
}
Possible output (with myfile.txt containing ABC):
1st character is A 2nd character is B 2nd character is B 2nd character is B
The example opens myfile.txt, then reads the first character once, and then reads 3 times the same second character.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4