无法在C中打开文件(Unable to open file in 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 }每当条件变为真时,如果(pFile == NULL),所以我无法对文件执行处理。
当我双击它时,我检查该驱动器中是否存在同名的文件,并将其正确打开
i am working in C and want to open a simple text file then perform some processing over it. 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.
I check that file exist in my drive with same name and its open properly when i double click on it
最满意答案
尝试把它放在if块中:
perror(NULL);这应该给出一个描述性的错误信息,所以你知道哪里出了问题。
Try putting this inside the if block:
perror(NULL);That should give a descriptive error message, so you know what went wrong.
更多推荐
发布评论