C11标准N1570工作草案在第306页"7.21.5.3 fopen功能"部分说
打开具有追加模式的文件('a'作为mode参数中的第一个字符)会导致对文件的所有后续写入强制转换为当前的文件结束,而不管是对fseek函数的中间调用....
任何人都可以确认不仅fseek功能而且其他文件定位功能如fsetpos和rewind都不能干预追加模式吗?
好吧,第338页的标准表示倒带与(void)fseek(stream,0L,SEEK_SET)类似,除了流的错误指示符也被清除.但据我在第337页阅读的标准,该标准没有说明fsetpos类似于fseek.
源代码来说明这个问题
#include <stdio.h>
// Declare the File Pointer
FILE *fp;
// Declare the test integer variable
int TEST;
// declare the test position variable for fsetpos test
fpos_t POSITION;
void WriteData(int choice){
// Clear the file content
fp = fopen("test.bin", "wb"); fclose(fp);
// Reopen the file with ab
fp = fopen("test.bin", "ab");
// Initialize the test integer variable …Run Code Online (Sandbox Code Playgroud)