【发布时间】:2017-12-27 18:29:49
【问题描述】:
以下代码的输出对我来说非常奇怪。谁能解释我为什么会这样?
#include<stdio.h>
int main()
{
int i=0;
char ch='a';
while(ch!='q')
{
scanf("%c",&ch);
printf("\t%d\n",i);
i++;
}
}
输出
【问题讨论】:
-
试试
scanf(" %c", &ch);另见:scanf() leaves the new line char in the buffer
标签: c while-loop scanf