小编Unk*_*123的帖子

rewind和fsetpos是否也可以干预C文件附加模式后续写入?

C11标准N1570工作草案在第306页"7.21.5.3 fopen功能"部分说

打开具有追加模式的文件('a'作为mode参数中的第一个字符)会导致对文件的所有后续写入强制转换为当前的文件结束,而不管是对fseek函数的中间调用....

任何人都可以确认不仅fseek功能而且其他文件定位功能如fsetposrewind都不能干预追加模式吗?

好吧,第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)

c standards file mode append

5
推荐指数
1
解决办法
439
查看次数

标签 统计

append ×1

c ×1

file ×1

mode ×1

standards ×1