C语言fseek()函数
作者:--
发布时间:2019-11-20
评论:0
阅读:0
fseek()函数用于将文件指针设置为指定的偏移量。它用于将数据写入所需位置的文件。
fseek()函数的语法:
int fseek(file *stream, long int offset, int whence)
fseek()函数中有3个常量用于whence参数的值,分别为:seek_set,seek_cur和seek_end。
示例:
创建一个源文件:fseek-file.c,其代码如下所示 -
#include <stdio.h>
void main() {
file *fp;
fp = fopen("myfile.txt", "w+");
fputs("this is h3 tutorial\n", fp);
fseek(fp, 7, seek_set);
fputs("maxsu", fp);
fclose(fp);
}
执行上面示例代码后,打开myfile.txt看到以下结果 -
this ismaxsuai tutorial