我尝试创建mydata.txt并从中读取,但编译器将结果显示为
0.000000 0.000000 168 2686832
此代码有什么问题?
int main()
{
double f_1, f_2;
int i_1, i_2;
FILE *file_pointer;
char file_name[SIZE] = "mydata.txt";
file_pointer = fopen(file_name, "w");
fprintf(file_pointer, "%f %f %d %d", 23.556, -76e5, 76, 5);
file_pointer = fopen(file_name, "r");
fscanf(file_pointer, "%lf %lf %ld %ld", &f_1, &f_2, &i_1, &i_2);
fclose(file_pointer);
printf("%f\n", f_1);
printf("%f\n", f_2);
printf("%d\n", i_1);
printf("%d\n", i_2);
getch();
return 0;
}
答案 0 :(得分:4)
在第二个fclose()
之前fopen()
。