简体   繁体   English

无法在C中打开文件

[英]Unable to open file in C

i am working in C and want to open a simple text file then perform some processing over it. 我正在C中工作,想要打开一个简单的文本文件,然后对其进行一些处理。 My code looks like 我的代码看起来像

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
    }

every time the condition becomes true if (pFile == NULL) so i am not able to perform processing on file. 每当条件变为true时,如果(pFile == NULL),那么我将无法对文件执行处理。

I check that file exist in my drive with same name and its open properly when i double click on it 我检查驱动器中是否存在相同名称的文件,并且双击该文件是否可以正确打开

Try putting this inside the if block: 尝试将其放入if块中:

perror(NULL);

That should give a descriptive error message, so you know what went wrong. 那应该给出描述性的错误信息,所以您知道出了什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM