2016-04-17 17 views
-2

我在C中使用CLion IDE進行編碼,並且我已經阻止了某事。CLion IDE中的文件I/O

#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++,併成功地工作。 我不知道這個問題

回答

0

r+模式意味着文件應該存在,看到http://www.cplusplus.com/reference/cstdio/fopen/

因爲你在當前目錄中使用絕對文件路徑,然後 節目搜索文件, Dev C++CLion明顯產生exe文件在不同的 目錄中,其中一個存在address.txt,另一個不存在。