为什么下面的程序同时产生两个输出信息,而不询问用户的任何输入?任何人都可以解释这个程序的输出吗?
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char input;
do {
printf("Enter a single character: \n");
scanf("%c", &input);
printf("The ordinal value is %d. \n",input);
} while(input != '#');
return 0;
}
输出为如下:
的,除非另行指定时间Enter a single character:
s
The ordinal value is 115.
Enter a single character:
The ordinal value is 10.
Enter a single character:
如果你想要健壮的基于行的用户输入,请查看http://stackoverflow.com/questions/4023895/how-to-read-string-entered-by-user-in-c/4023921#4023921 – paxdiablo 2011-03-20 01:52:22