c - 为什么在 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内容的终端。
如果我在运行 program_1 时检查 myfile 的内容,则不会打印字符串“test”。
但是,如果我在运行 program_1 时输入一次回车键并检查 myfile 的内容,我可以看到“test”字符串已打印出来。
问题:为什么会这样?
解决方案
推荐阅读
- javascript - 铬画布上悲伤的脸
- python - Keras深度学习准确率100%的问题
- go - 为什么 GDB 显示大地图的所有零值
- devextreme - DevExtreme Angular DataGrid - 自定义分组面板和操作
- java - 内部地图和平面地图如何在 java 8 中工作
- ruby - 快速将字符串拆分为多个数组
- android - 如何在启动时从覆盖 Windows 服务中移除焦点?
- google-cloud-platform - 合并两个 PCollection(Apache 梁)
- css - 多部分 css 选择器的最终目标
- angular - 在 ionic 4 中使用 router.navigate 时,构造函数或 ngoninit 没有调用,有角度