不是这个:
char fname[256];
printf("Enter file name\n");
scanf("%123s",fname);
strcat(fname,".txt"); F
FILE *inputf; inputf=fopen(fname,"w"); // <--!!!
if (inputf!=NULL) printf("found");
else printf("not found");
but this instead:
char fname[256]; FILE *inputf;
inputf=fopen(fname,"w");
printf("Enter file name\n");
// you know that you can't ever, EVER use scanf() so // remove this time bomb and use something else scanf("%123s",fname);
strcat(fname,".txt"); inputf=fopen(fname,"w"); if (inputf!=NULL) { printf("found"); } else { printf("not found"); }
现在,什么指针不是NULL?你不能像编译代码那样编译代码,那么你怎么知道什么是或不是NULL?
--pete
什么问题? – Gorgen 2011-03-01 06:18:17
你在什么环境下运行这段代码?你自己的电脑?共享终端,可能是学校电脑? Ssh访问别的地方?如果你正在运行linux,“ls -l”的输出是什么?因为它似乎缺少写入文件系统的权限。 – 2011-03-01 06:42:11
你的代码在我的系统上编译得很好。如果不以“w”参数退出,它会创建文件。你必须检查@junjanes建议的内容。 – Mahesh 2011-03-01 06:43:51