【问题标题】:File I/O in CLion IDECLion IDE 中的文件 I/O
【发布时间】:2016-08-09 06:24:25
【问题描述】:

我正在使用 CLion IDE 进行 C 编码,但我在某事中被阻止了。

#include<stdio.h>

int main()
{
    FILE* f;
    f = fopen("address.txt", "r+");
    if(f == NULL){
        printf("File Open Error!");
        return 0;
    }

    char str[100][100];
    for(int i = 0 ; i < 100 ; i ++){
        fscanf(f, "%s", str[i]);
    }
    fclose(f);
    f = fopen("out.txt", "w+");
    for(int i = 0 ; i < 100 ; i ++){
        fprintf(f, "%s\n", str[i]);
    }
    return 0;
}

CLion 告诉我“文件打开错误”。 因此,我尝试了 DEV C++,并成功运行。 我不知道这个问题

【问题讨论】:

    标签: c file-io clion


    【解决方案1】:

    r+模式表示文件应该存在,见http://www.cplusplus.com/reference/cstdio/fopen/

    因为你没有使用绝对文件路径,那么 当前目录中的程序搜索文件, Dev C++CLion 显然会生成不同的 exe 文件 目录,其中一个 address.txt 存在,另一个不存在。

    【讨论】:

      猜你喜欢
      • 2010-11-06
      • 2015-11-28
      • 1970-01-01
      • 2012-05-01
      • 2010-12-25
      • 2011-08-07
      • 1970-01-01
      • 2013-09-22
      • 2015-11-13
      相关资源
      最近更新 更多