C fseek()

The fseek() function is used to set the file pointer to the specified offset. It is used to write data into file at desired location.

Syntax:

snippet
int fseek(FILE *stream, long int offset, int whence)

There are 3 constants used in the fseek() function for whence: SEEK_SET, SEEK_CUR and SEEK_END.

Example:

snippet
#include 
void main(){
   FILE *fp;

   fp = fopen("myfile.txt","w+");
   fputs("This is rookienerd", fp);
  
   fseek( fp, 7, SEEK_SET );
   fputs("sonoo jaiswal", fp);
   fclose(fp);
}

myfile.txt

Output
This is sonoo jaiswal
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +