首页 > 解决方案 > 为什么在 C 中执行期间不保存文件?

问题描述

program_1的源代码如下。

/* program_1.c */

#include <stdio.h>

int main(void)
{
FILE *ofp;

ofp = fopen("myfile", "w");

fprintf(ofp, "test");

getchar();

fclose(ofp);

getchar();

return 0;

}

首先显示运行一个program_1的终端和另一个查看myfile内容的终端。

  1. 如果我在运行 program_1 时检查 myfile 的内容,则不会打印字符串“test”。

  2. 但是,如果我在运行 program_1 时输入一次回车键并检查 myfile 的内容,我可以看到“test”字符串已打印出来。

问题:为什么会这样?

标签: cfilestreamfclose

解决方案


推荐阅读