#include <stdio.h>
#include <stdlib.h>
int main()
{
char c[1000];
FILE *fptr;
if ((fptr = fopen("program.txt", "r")) == NULL)
{
printf("Error! opening file");
// Program exits if file pointer returns NULL.
exit(1);
}
// reads text until newline
fscanf(fptr,"%[^\n]", c);
printf("Data from the file:\n%s", c);
fclose(fptr);
return 0;
}
输出错误!打开文件
我在同一目录中有程序和 txt 文件。 如何直接访问该文件?
最佳答案
要进行诊断,请根据您的平台使用system 命令发出ls 或dir。那会告诉你你从哪里跑。很可能它与您尝试打开的文件所在的位置不同。
关于无法打开txt文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47580897/