User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed


Table of Contents


    int fsetpos(FILE *stream, const fpos_t *pos); 

reset the position indicator to using fsetpos() stores the current file position indicator to the location indicated by the information in pos Returns non-zero on error.

C Sourcecode Example

#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
int main( void )
    FILE *stream;
    fpos_t file_pos;
    int c;
    int 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("%c", c);
   printf("1st Position of # is the %d Byte\n", file_pos);
   printf("\nset to given position\nand print it again\n");
   fsetpos(stream, &file_pos);
   while((c = fgetc(stream) ) != EOF) {
        printf("%c", c);


  output:  ./fsetpos 
  test 1234,
   ... # ...
  this is a test for 
  1st Position of # is the 17 Byte
  set to given position
  and print it again
  this is a test for

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/fsetpos.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz