【发布时间】:2011-11-17 12:19:20
【问题描述】:
我的代码如下
typedef struct
{
char name[15];
char country[10];
}place_t;
int main()
{
int d;
char c;
place_t place;
printf("\nEnter the place name : ");
scanf("%s",place.name);
printf("\nEnter the coutry name : ");
scanf("%s",place.country);
printf("\nEnter the type of the place : Metropolitan/Tourist (M/T)?");
scanf("%c",&c);
printf("You entered %c",c);
return 0;
}
如果我运行程序,它会提示输入地名和国名,但从不等待用户输入的字符。
我试过了
fflush(stdin);
fflush(stdout);
都不行。
注意:如果我编写类似的代码来获取整数或浮点数,而不是字符,它会提示输入值并且代码可以正常工作。
int d;
printf("\nEnter the type of the place : Metropolitan/Tourist (M/T)?");
scanf("%d",&d);
为什么会这样?代码有什么问题吗?
【问题讨论】: