English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The fseek() function is used to set the file pointer to the specified offset. It is used to write data to the required position in the file.
Syntax:
int fseek(FILE *stream, long int offset, int whence)
The first parameter stream is the file pointer
The second parameter offset is the offset, an integer represents positive offset, and a negative number represents negative offset
The third parameter whence sets where to start the offset, and can use3one of the constants, which may have values: SEEK_CUR, SEEK_END, or SEEK_SET
SEEK_SET - beginning of the file
SEEK_CUR - current position
SEEK_END - end of the file
Among them, SEEK_SET, SEEK_CUR, and SEEK_END can also be used in sequence as 0,1 and 2indicates.
#include <stdio.h> void main() { FILE *fp; fp = fopen("myfile.txt","w")+ fputs("This is w"3codebox.com", fp); fseek(fp, 7, SEEK_SET ); fputs("Seagull Ali", fp); fclose(fp); }
myfile.txt
This is Seagull Ali