A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/cstdio/fgetpos/ below:

function

<cstdio>

fgetpos
int 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.



Parameters
stream
Pointer to a FILE object that identifies the stream.
pos
Pointer to a fpos_t object.
This should point to an object already allocated.

Return Value On success, the function returns zero.
In case of error, errno is set to a platform-specific positive value and the function returns a non-zero value.

Example
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.



See also
fsetpos
Set position indicator of stream (function)
ftell
Get current position in stream (function)
fseek
Reposition stream position indicator (function)

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