文件怎么没法成功打开?
#include<stdio.h>
#include<stdlib.h>
main()
{
FILE *fp;//申明文件指针fp,用来保存建立文件的地址
char filename[40],mode[5];
while(2)
{
printf("Enter a filename:");
gets(filename);//从键盘输入文件名,放到字符数组filename中存放
printf("Enter a mode(max 3 characters):");//输入文件模式,放到字符数组mode中
gets(mode);
if((fp=fopen(filename,mode))!=NULL)
{//以输入的模式打开文件
printf("Successful opening %s in mode %s\n",filename,mode);
fclose(fp);//关闭打开的文件
puts("Enter x to exit,any other to continue.");//按下x键,程序结束
if((getche())=='x')
break;
else
continue;
}
else
{
printf("Error opening file %s in mode %s\n",filename,mode);
puts("Enter x to exit,any other to continue.");//按下x键,程序结束
if((getche())=='x')
break;
else
continue;
}//else分支结束
}//while分支结束
}//主函数结束
假如我在E盘下有一文件1.c
运行该程序时让我输入文件名:e:\\1.c
让我输入打开模式:r
结果没打开啊?????
为什么呢?请高手指教,先谢谢了!