使用scanf后程序崩溃(Program crashing after using scanf)

编程入门 行业动态 更新时间:2024-10-25 14:35:56
使用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.

更多推荐

本文发布于:2023-08-07 11:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464206.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   scanf   crashing   Program

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!