我的代码( gist link )
//pre-processor directives
#include <stdio.h>
#include <math.h>
//Main function
int main() {
int month, day, year, lowest_temp, highest_temp;
float temp;
char fname[30];
FILE * ifp;
printf("Tell me about your dragon's preferred temperature for flying: What is the coldest temperature they can fly in?\n");
scanf("%d", lowest_temp);
printf("What is the hottest temperature they can fly in?\n");
scanf("%d", highest_temp);
printf("Please enter the name of the weather data file for Dragon Island.\n");
scanf("%s", fname);
ifp = fopen(fname, "r");
fscanf(ifp, "%d %d %d %f, &month &day &year &temp");
printf("%d %d %d %f, &month &day &year &temp");
return 0;
}
首次扫描后崩溃没有错误
如果你能告诉我错误是什么,我会很感激。另外,如果你可以帮助我解决我的问题的下一步,那将是非常棒的。
我的任务 https://gist.github.com/anonymous/e9292f14b2f8f71501ea/88e9e980632871f1f1dedf7589bb518f1bba43e8
答案 0 :(得分:3)
scanf("%d", lowest_temp);
...
scanf("%d", highest_temp);
%d
要求int
参数的地址只传递int
变量。传递他们的地址 -
scanf("%d",&lowest_temp);
...
scanf("%d",&highest_temp);
这两个陈述 -
fscanf(ifp, "%d %d %d %f, &month &day &year &temp");
printf("%d %d %d %f, &month &day &year &temp");
应该是 -
fscanf(ifp, "%d %d %d %f", &month &day &year &temp);
printf("%d %d %d %f", month ,day,year ,temp);