小编Al.*_*Al.的帖子

追加 C 失败,只需覆盖

而不是附加“abc”(从而最终得到一个充满 abcabcabc 的文件......),无论我运行多少次,我的文件只包含“abc”......我怎样才能附加?

#include <stdio.h>
#include <string.h>

int main(){
    char strng[10];
    strcpy(strng,"abc");
    FILE *my_file;
    my_file = fopen("myfile","a+");
    if (my_file == NULL){ printf("problem\n");}
    fwrite(strng, sizeof(strng), 1, my_file);
    printf("appending %s\n",strng);
    fclose(my_file);
}
Run Code Online (Sandbox Code Playgroud)

c file-io

5
推荐指数
0
解决办法
8964
查看次数

标签 统计

c ×1

file-io ×1