扫描C中的int后无法扫描char变量

扫描C中的int后无法扫描char变量,c,C,我在扫描字符变量时遇到问题,我的代码是 #include <stdio.h> #include <conio.h> void main() { clrscr(); int a; float b; char c; printf("Enter value for int variable \n"); scanf("%d",&a); printf("Enter value for float variable \n"); scanf("%f",&b);

我在扫描字符变量时遇到问题,我的代码是

#include <stdio.h>
#include <conio.h>

void main() 
{
clrscr();
int a;
float b;
char c;

printf("Enter value for int variable \n");
scanf("%d",&a);

printf("Enter value for float variable \n");
scanf("%f",&b);

printf("Enter value for char variable \n");
scanf("%c",&c); //scanning is automatically skipped !!! 

getch();
}
#包括
#包括
void main()
{
clrsc();
INTA;
浮球b;
字符c;
printf(“输入int变量的值\n”);
scanf(“%d”和“&a”);
printf(“为浮点变量输入值”);
scanf(“%f”和“b”);
printf(“输入char变量的值\n”);
scanf(“%c”,&c);//扫描将自动跳过!!!
getch();
}
请告诉我,为什么会发生这种情况,我能做些什么来解决它

由于存储了enter键,按下[被视为字符输入]。使用一个
getch()在第三个
scanf()
之前


或者,使用
(scanf(“%c”,&c);)
[注意
%c
]之前的空格,这将消除实际输入之前存在的任何数量的空白[缓冲]字符。

在新行之后,SOI上的多个副本将在传递给
scanf
的每个字符串末尾添加
'\n'