我正在使用 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”的值放入文件中。请你知道答案让我知道,我该怎么办?