How to use fsetpos() function to set the position of file pointer in C

1 Answer

0 votes
#include <stdio.h>
   
int main(void)
{
	FILE *fp = fopen("d:\\data.txt", "w");

    if (fp == NULL) 
	{
		perror("Error open file");
		return 1;
	}
	fpos_t pos;
	
	fgetpos(fp, &pos);
	printf("pos = %I64d\n", pos);
	
	fputs("programming is fun", fp);
	fsetpos(fp, &pos);
	fputs("c programming is fun", fp);	
	
	fclose(fp);
	
    return 0;
}
  
// file content: c programming is fun
  
/*
run:
  
pos = 0

*/

 



answered May 5, 2016 by avibootz

Related questions

...