C语言中用scanf()连续输入两个字符时的问题
(2013-10-19 08:01:10)| 标签: it | 分类: C语言 | 
遇到同样的问题,待验证
#include
int main()
{
char ch1,ch2;
printf("Input for ch1:\n");
scanf("%c",&ch1);
printf("ch1=%c\n",ch1);
printf("Input for ch2:\n");
scanf("%c",&ch2);
printf("ch2=%c\n",ch2);
} 
 
 
ps:本题其实不用那么麻烦,scanf("%c%c",&ch1,&ch2);一句就可以搞定了,上面只是介绍下解决问题的方法。
 
另外:
1.scanf("%d%d",&x,&y);时,输入必须为10 20(注:10和20之间要用空格,回车或TAB键之中的任选一种隔开)
2.scanf("%d,%d",&x,&y);时,输入必须为10,20
3.scanf("%d+%d",&x,&y);时,输入必须为10+20

 加载中…
加载中…