CLion IDE中的文件I / O.

时间:2016-04-17 15:15:12

标签: c file-io clion

我正在使用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告诉我&#34;文件打开错误&#34;。 所以,我尝试了DEV C ++,并且成功地工作了。 我不知道这个问题

1 个答案:

答案 0 :(得分:0)

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

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