【发布时间】:2011-04-01 10:17:51
【问题描述】:
首先,我的英语不太好..请理解:)
当我尝试使用 fopen() 和 gvim 打开文本文件来写一些东西时,例如FILE *f = fopen("data.txt", "w");,我在任何地方都找不到 data.txt 文件。不仅是当前目录,而且在 Windows 资源管理器中。但是..没有文件它工作正常。 :|
我有疑问,所以我试过这个FILE *f = fopen("c:\my\..."data.txt", "w");指定路径,工作得很好!
我知道文本文件与执行文件夹存储在同一文件夹中。
当然,其他 IDE 运行良好。(MSVS 或 Dev C++) 我有什么问题??
(我使用的是 Windows7 和 gvim。)
// Modification
// source code
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f = NULL;
int name[10];
if((f = fopen("data.txt", "w")) == NULL){
printf("sorry..\n");
system("pause");
exit(1);
}
fprintf(f, "%s\n", "Dennis");
fclose(f);
if((f = fopen("data.txt", "r")) == NULL){
printf("sorry2..\n");
system("pause");
exit(1);
}
fscanf(f, "%s", name);
printf("%s\n", name);
fclose(f);
system("pause");
return 0;
} // I think it's no problem. I've tried different ways to try several times.
我会编译这个 -> 地图:! gcc % -o %<.exe vimrc. cntl f9 vim fopen fscanf windows>
【问题讨论】:
-
我怀疑这与您使用 gvim 的事实有关。
-
你能用五行或十行代码重现这个问题,你可以在这里粘贴吗?
-
每次都要指定路径吗?很麻烦。。
-
给萨诺德。当然。但很难看到:)
-
if((f = fopen("data.txt", "w")) == NULL) { 一些警告并退出.. } fprintf(f, "%s\n", "丹尼斯"); f关闭(f); if((f = fopen("data.txt", "r")) == NULL) {...} fscanf(f, "%s", name); f关闭(f); // 文件不存在,但正在工作。就是这样。。