Help us and donate little Bitcoins to pay the server costs: 1AXLPuRUBYc1JczTW4XS65GL6oWjNP2Vt2

User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

because of the inhumane working conditions at amazon in Germany, I will offer the Amazon app no more! (ARD Reportage)


    int fgetpos(FILE *stream, fpos_t *pos);

Stores current file position for stream stream in *pos. Returns non-zero on error.


The fgetpos() function stores the file position indicator of the given file stream in the given position variable.
The position variable is of type fpos_t (which is defined in stdio.h) and is an object that can hold every possible position in a FILE.
fgetpos() returns zero upon success, and a non-zero value upon failure.

C Sourcecode Example

 * fgetpos example code
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
int main( void )
    FILE *stream;
    fpos_t file_pos;
    int c,i;
    if((stream=fopen("test.txt","r"))==NULL) {
        printf("Cannot open file.\n");
        return 1;
    fgetpos(stream, &file_pos); 
    while((c = fgetc(stream) ) != EOF) {
     if ( c == '#' ){ 
             fgetpos(stream, &file_pos); 
        printf("character is:  %c\n", c);
      printf("1st Position of # is the %d Byte\n", file_pos);
return 0;

fgetpos example output

  output: ./fgetpos 
  character is:  L
  character is:  i
  character is:  n
  character is:  e
  character is:   
  character is:  1
  character is:  
  character is:  #
  .... and so on
  1st Position of # is the 24 Byte
c/stdio.h/fgetpos.txt · Last modified: 2013/02/17 03:59 by

The new Question & Answer System is online and waiting for your Questions about Programming problems Impressum