fseek() in file handling by R4R Team

- fseek() is the function that change the position of the file pointer to specified location in file.

Syntax-
fseek(file_pointer,pos,SEEK_SET);


program-

#include < stdio.h>
void main(){
FILE *fp;
fp = fopen("Myfile.txt","w+");
//write data in file
fputs("It was my old data which i store", fp);
//Now change the position of file pointer to 7
fseek( fp, 7, SEEK_SET );
//Again write data with current file pointer position
fputs("This is my data after seek set to 7", fp);
fclose(fp);
}


At this state:
Myfile.txt looks like:


output-

It was my data after seek set to 7




Leave a Comment: