一个有关C语言scanf的问题 运行到scanf()时还没有输入,为什么自动执行下面的语句了?
我的main函数式这样的intmain(){chari;printf("Hellodearcustomerwelcometouseflightsystem!\n");wh...
我的main函数式这样的
int main()
{
char i;
printf(" Hello dear customer welcome to use flight system! \n");
while(1)
{
printf("**************************************************************************\n");
printf(" choose the function you want:\n");
printf(" 1.check your ticket wether it has been booked successfully or not.\n");
printf(" 2.reserve a new ticket:\n");
printf(" 3.cancel a ticket:\n");
printf(" 4.print all the booked tickets' info:\n");
printf(" 5.exit the system.\n");
printf("**************************************************************************\n");
printf("\n");
scanf("%c",&i);
printf(" > <||| i is:%c\n",i);
if(i=='1')
{
check(A);
}
else if(i=='2')
{
reserve(A);
}
else if(i=='3')
{
printf("Please input the ticket number: ");
char ticket_no[10];
scanf("%s",ticket_no);
cancel(A,ticket_no);
}
else if(i=='4')
print(A);
else if(i=='5')
{
break;
}
else
{
printf("A incorrect choice please make another choice!\n");
continue;
}
}
运行结果是这样的:
我就不明白 明明还没输入i呢 为什么程序就往下执行了呢?求大神指导(鞠躬)~ 展开
int main()
{
char i;
printf(" Hello dear customer welcome to use flight system! \n");
while(1)
{
printf("**************************************************************************\n");
printf(" choose the function you want:\n");
printf(" 1.check your ticket wether it has been booked successfully or not.\n");
printf(" 2.reserve a new ticket:\n");
printf(" 3.cancel a ticket:\n");
printf(" 4.print all the booked tickets' info:\n");
printf(" 5.exit the system.\n");
printf("**************************************************************************\n");
printf("\n");
scanf("%c",&i);
printf(" > <||| i is:%c\n",i);
if(i=='1')
{
check(A);
}
else if(i=='2')
{
reserve(A);
}
else if(i=='3')
{
printf("Please input the ticket number: ");
char ticket_no[10];
scanf("%s",ticket_no);
cancel(A,ticket_no);
}
else if(i=='4')
print(A);
else if(i=='5')
{
break;
}
else
{
printf("A incorrect choice please make another choice!\n");
continue;
}
}
运行结果是这样的:
我就不明白 明明还没输入i呢 为什么程序就往下执行了呢?求大神指导(鞠躬)~ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询