无法打开txt文件

标签 c file

#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 命令发出lsdir。那会告诉你你从哪里跑。很可能它与您尝试打开的文件所在的位置不同。

关于无法打开txt文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47580897/

相关文章:

c - 使用 sscanf() 基于分隔符读取多个字符串

python - 工作流程: C pointer to Python array?

java - 查找 .jar 文件运行的文件的名称

python - 为什么 Python 在不应该的时候给我 "an integer is required"?

带有进度条的仅 JavaScript 文件 uploader

c - 如果我选择首先在 Linux 上进行开发,我该如何进行跨平台开发?

c - 读取自己的源文件和文本文件行号?

c - gtk 初学者应用程序无法在断言失败的情况下工作

wpf - Caliburn.Micro 在 WPF 中拖放文件

python:删除非空目录