无法在C中打开文件

时间:2011-03-30 10:25:47

标签: c

我在C中工作,想要打开一个简单的文本文件,然后对其执行一些处理。我的代码看起来像

FILE *pFile;
pFile = fopen("d:\\series.txt", "r");

if (pFile == NULL)
{
    printf("File not found or Unable to open file\nPress any key to continue . . ." );
        getch();
        return;
    }   
    else
    {
         //process here
    }

每次条件成立时     if(pFile == NULL) 所以我无法对文件进行处理。

我检查我的驱动器中是否存在同名文件,当我双击它时它正常打开

1 个答案:

答案 0 :(得分:8)

尝试将其放入if块内:

perror(NULL);

这应该给出描述性错误消息,以便您知道出了什么问题。