fopen() returning a NULL pointer, but the file definitely exists

前端 未结 7 812
不思量自难忘°
不思量自难忘° 2020-12-31 02:25

The code I have is as follows:

FILE *txt_file = fopen(\"data.txt\", \"r\");
if (txt_file == NULL) {
    perror(\"Can\'t open file\");
} 

Th

7条回答
  •  悲&欢浪女
    2020-12-31 02:55

    I just had a similar issue like this where I knew the path was correct and the file was in the right location. Check the file permissions. It is possible that the program cannot access the file because it is getting permission denied.

提交回复
热议问题