【发布时间】:2011-05-13 01:11:52
【问题描述】:
我正在使用 Dev-C++ IDE,现在我正在尝试处理文件。这是我的代码:
int main(){
FILE *fp;
int b = 10;
int f;
fp = fopen("data.txt", "w");
//checking if the file exist
if(fp == NULL){
printf("File does not exist,please check!\n");
}else{
printf("we are connected to the file!\n");
}
fprintf (fp, " %d ", b) ;
fclose(fp);
printf("Reading from the file \n");
FILE *fr;
fr=fopen("data.txt","r");
fscanf (fr, " %d ", &f) ;
fclose(fr);
printf("the data from the file %d \n", f);
return 0;
}
此代码在 NetBeans 中工作,但在 Dev-C++ 中,我只是收到“我们已连接到文件”的消息,但它没有将“10”的值放入文件中。请你知道答案告诉我,我该怎么办?
【问题讨论】:
-
@user261002;你看到任何没有内容的文件吗?还是根本没有文件?
-
您应该做的第一件事是切换 IDE。 DevC++ 已经死了,还有更好的替代品(Visual Studio express、Code::Blocks 等)
-
它创建了文件,但没有写入文件。
标签: c file file-handling dev-c++