急急急!!!在线等C语言scanf函数scanf("%c%c", c1, c2);在键盘上如何输入

# include "stdio.h"

int main()
{
int a, b;
float x, y;
char c1, c2;

scanf("a = %db = %d", &a, &b);
scanf("%f%e", &x , &y);
scanf("%c%c", &c1, &c2);
printf("%d %d\n", a, b);
printf("%f %f\n", x, y);
printf("%c %c\n", c1, c2);
return 0;
}
在VC++6.0中的输出结果是:
————————————————————
a = 3b = 7
8.5 71.82
A a
3 7
8.500000 71.820000

A
Press any key to continue
——————————————-—————--
结果中最后一行的 'a' 怎么没了???应该如何输入数据呢???
最新回答
泽城美雪

2024-09-29 01:43:57

scanf("%c", &c1);
// add a new scanf here or gets to delete " " in I(input) stream ex: scanf("%c", &c2);
scanf("%c", &c2);
追问
I try ,but it does not work
追答
You can try get(), but not scanf.
Scanf is not well support in C++, you'd better not use this function.
独白

2024-09-29 02:29:14

scanf可以读回车。scanf(" %c%c", &c1, &c2);你在%c前加个空格试试
追问
试了,a还是输不出来
追答
scanf("空格%c%c", &c1, &c2),输入Aa,不行吗
追问
紫竹語嫣

2024-09-29 10:06:04

scanf("%c%c", &c1, &c2);改为scanf("%c %c", &c1, &c2);就ok了。
追问
还是不OK啊
瑾沫流年

2024-09-29 01:41:46

scanf("%c%c", &c1, &c2);

空格也是一个字符,所以你的输入使c1=‘A’ c2=' '
追问
我输入  Aa  中间不加空格也没有a输出啊?
夏迟归

2024-09-29 00:46:43

scanf(" %c %c", &c1, &c2); 输入A a