有人能告诉我为什么文件不会改变?它适用于我使用rewind或fseek不使用的情况.
什么是使用fputs后的标准方式fgets.文件指示器位于第9位,因此fputs必须在此之后写入,但它不会执行任何操作.
在档案中:
abcd efgh ijkl mnor
Run Code Online (Sandbox Code Playgroud)
在源代码中:
char c;
char str[15];
FILE *fp = fopen("d:\\data.txt","r+");
fgets(str, 10, fp);
// fseek(fp, 9, SEEK_SET);
// rewind(fp);
printf("%d\n", ftell(fp));
// ftel shows that it's in "9".
printf("%s", str);
fputs(str, fp);
// why its not working
fclose(fp);
Run Code Online (Sandbox Code Playgroud)