[英]Crash after first scanf novice c programming
我的代碼( 要點鏈接 )
//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
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.