📅  最后修改于: 2020-09-25 08:24:21             🧑  作者: Mango
int fsetpos(FILE* stream, const fpos_t* pos);
fsetpos()
函数将文件流和指向fpos_t
对象的指针作为参数,该对象是通过调用fgetpos()获得的。
它在
成功时, fsetpos()
函数将返回零,否则返回非零。
#include
int main()
{
FILE *fp;
fpos_t pos;
int c;
fp = fopen("myfile.txt","w+");
fputs("What a boring day!\n",fp);
fgetpos(fp, &pos);
fputs("The weather is bad",fp);
fsetpos(fp, &pos);
/* Replaces the second line by new string */
fputs("It is raining badly.",fp);
rewind(fp);
while(!feof(fp))
{
c = getc(fp);
putchar(c);
}
fclose(fp);
return 0;
}
运行该程序时,输出为:
What a boring day!
It is raining badly.