2016-02-03 40 views
2

這是我編寫的一個程序,它可以計算飛機着陸時間,當您給出起飛時間並飛行一秒鐘。但是當我運行一個程序並在控制檯中插入第一個數字時,它立即崩潰。使用scanf後程序崩潰

#include <stdio.h> 

int main (void) { 
    int m, s; 
    int u; 
    long flight, landing; 

    printf("insert time of taking a plane:\n time in hours: "); 
    scanf("%d, &u"); 
    printf(" minutes: "); 
    scanf("%d", &m); 
    printf(" seconds: "); 
    scanf("%d", &s); 
    printf("Duration of a flight (in seconds): "); 
    scanf("%ld", &flight); 
    pristanek = u * 3600 + m * 60 + s + let; 
    u = landing/3600; 
    m = (landing % 3600) % 60; 
    s = landing % 60; 
    printf("Time of landing; %d:%02d:%02d\n", u, m, s); 
    return 0; 
} 

回答

4

也正是由於這樣的事實,爲scanf正確的語法是:

scanf("%d", &u); // notice the " is after the "d" 

實際上,你這樣做是正確在你的其他scanf秒。