这是我编写的一个程序,当您给定飞机起飞时间并飞行一秒钟时,它会计算飞机着陆的时间。但是,当我运行程序并在控制台中插入第一个数字时,它立即崩溃。
#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;
}
最佳答案
这是因为 scanf
的正确语法是:
scanf("%d", &u); // notice the " is after the "d"
您实际上在其他 scanf
中得到了正确的结果。
关于c - 使用 scanf 后程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35183013/