使用scanf后程序崩溃(Program crashing after using 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; }This is a program I wrote that calculates time of landing a plane when you give it starting time and it flies for a second. But when I run a program and insert the first number in the console it immediately crashes.
#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得到了它。
It is due to the fact that the correct syntax for scanf is:
scanf("%d", &u); // notice the " is after the "d"You actually got it right in your other scanfs.
更多推荐
发布评论