例如:FILE *pf=fopen(“F:\1.txt”,"w");
fputs("jhhhbjuh",pf);
char ch=fgetc(pf);
clearerr(pf);
fputs("asdffffff",pf);
我想问最下方的fputs能操作成功吗?为什么?
可以成功,不过你的fgets使得文件指针已经后移了1个字节,所以最好fseek向前一个字节
void main()
{
FILE *pf=fopen("F:\\1.txt","w");
fputs("jhhhbjuh",pf);
char ch=fgetc(pf);
clearerr(pf);
fseek(pf,-1,SEEK_CUR);
fputs("asdffffff",pf);
}
The clearerr function resets the error indicator and end-of-file indicator for stream. Error indicators are not automatically cleared; once the error indicator for a specified stream is set, operations on that stream continue to return an error value until clearerr, fseek, fsetpos, or rewind is called.