无法在C中打开文件(Unable to open file in C)

编程入门 行业动态 更新时间:2024-10-11 01:10:31
无法在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.

更多推荐

本文发布于:2023-08-08 00:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466681.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Unable   file   open

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!