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 CloudsNClear”, fp);
fseek( fp, 7, SEEK_SET );
fputs(“Rohit Sharma”, fp);
fclose(fp);
}
myfile.txt
This is Rohit Sharma
Related Post:
Features of C Programming Language
Dynamic memory allocation in C
Difference Between Type Casting and Type Conversion in C
Difference Between Variables and Constants
C Program to generate Fibonacci Triangle
C Program to print “hello” without semicolon
C Program to swap two numbers without third variable
Count the number of digits in C