Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Saturday 1 June 2019

C fseek() function


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:
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:

#include <stdio.h>  
void main(){  
   FILE *fp;  
  
   fp = fopen("myfile.txt","w+");  
   fputs("This is javaabhigyan", fp);  
    
   fseek( fp, 7, SEEK_SET );  
   fputs("Abhigyan", fp);  
   fclose(fp);  
}  
myfile.txt

This is Abhigyan

0 comments:

Post a Comment