【发布时间】:2021-03-26 06:44:12
【问题描述】:
#include <stdio.h>
void main() {
int i;
char x;
float y;
double z;
//line1
printf("enter an integer");
scanf("%d", &i);
//line3
printf("enter a character");
scanf("%c", &x);
printf("enter a floating point");
scanf("%f", &y);
printf("enter a double");
scanf("%lf", &z);
printf("Integer is %d \n character is %c \n floating point is %f \n double is %lf ",
i, x, y, z);
}
我的问题是,当我运行此代码时,它不会提示输入字符值并跳到下一个命令。但是,如果我将第 3 行与 1 交换,即如果我先提示输入字符然后输入整数,那么它可以正常工作。请帮我理解这个问题。
【问题讨论】:
-
不是您要的,但您可能还想在提示末尾添加换行符,或者,如果您不想要换行符,则明确
fflush()stdout,否则您可以运行进入输出缓冲,防止您的提示出现在控制台上。 -
这么多重复!