麻烦使用输入scanf()的 [英] Trouble with input using scanf()

查看:149
本文介绍了麻烦使用输入scanf()的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C,所以我有一点麻烦,scanf()的。

I'm new to C so I'm having a bit of trouble with scanf().

#include <stdio.h>
#include <stdlib.h>

int main()
{
int height;
int weight;

printf("Enter height in inches:\n");
scanf("%d", &height);

printf("Enter weight in pounds:\n");
scanf("%d", &weight);

printf("You are %d inches tall and weigh %d pounds.", height, weight);

return 0;
}

我是pretty确信这是正确的语法,但是当我运行它,它会显示一个空的屏幕和我输入2个数字后显示:

I'm pretty sure this is the correct syntax but when I run it, it shows an empty screen and after I input 2 numbers it shows:

64

120

在输入英寸高度:

在磅体重输入:

您64英寸高,体重120磅。

You are 64 inches tall and weigh 120 pounds.

据一些教程,它应该显示中输入英寸高度::之前,我输入第二个号码前输入我第一号和磅体重输入。请帮帮我!

According to some tutorials, it's supposed to display "Enter height in inches:" before I input the 1st number and "Enter weight in pounds:" before I input the 2nd number. Please help me!

我使用Eclipse来写我的程序和MinGW的编译器,如果这是相关的。

I'm using Eclipse to write my programs and MinGW as the compiler if that's relevant.

推荐答案

它是一种的错误在Eclipse ,这已经被大多数人使用Eclipse和MinGW的报道。

Its a bug in eclipse and this has been reported by most of the people using eclipse and MinGW.

要克服这个问题,你可以使用 fflush(标准输出)每次调用的printf 之后或使用以下在开始

To overcome this problem, you could use fflush(stdout) after every call to printf or use the following in the start of main :

setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);

这将导致标准输出标准错误刷新立即每当被写入。

This will cause stdout and stderr to flush immediately whenever it is written to.

这篇关于麻烦使用输入scanf()的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆