源程序如下
#include<stdio.h>
#include<ctype.h>
int main()
{
int c;
FILE *fp;
char filename[81];
printf("please enter the file name:");
gets(filename);
if((*filename)=='\0')
{
puts("No filename enter.");
return -1;
}
fp=fopen("in.txt","R");
if(!fp)
{
puts("Error,file name is not found.");
return -1;

}
while((c=fgetc(fp))!=EOF)
putchar(toupper(c));
fclose(fp);
return 0;}运行后老是Error,file name is not found
请指教

解决方案 »

  1.   

    你的代码是输入了文件名之后打开in.txt读取,但是真的有这个文件存在吗?个人认为从代码的逻辑性上来讲,应该是:
    fp=fopen(filename,"R");
      

  2.   

    你可以先用puts看得到的文件名是否正确。
      

  3.   

    不好意思,源程序是
    #include<stdio.h>
    #include<ctype.h>
    int main()
    {
    int c;
    FILE *fp;
    char filename[81];
    printf("please enter the file name:");
    gets(filename);
    if((*filename)=='\0')
    {
    puts("No filename enter.");
    return -1;
    }
    fp=fopen(filename,"R");
    if(!fp)
    {
    puts("Error,file name is not found.");
    return -1;

    }
    while((c=fgetc(fp))!=EOF)
    putchar(toupper(c));
    fclose(fp);
    return 0;}
    还是Error,file name is not found,
    上面用in.txt是我自己调试时改的,也不对
      

  4.   

    我用调试看过,读入的文件名是对了,可是fopen后的文件指针总是空的
      

  5.   

    你的路径是什么样的形式fp = fopen("c:data.txt","R");//c盘下的data.txt文件
      

  6.   

    faint 上面少了最重要的
    fp = fopen("c:\\data.txt","R");//c盘下的data.txt文件
      

  7.   

    好像 fopen()返回的仍是NULL,我要崩溃了
      

  8.   

    用GetLastError() 看看是什么错误。