[求助]没有预料的问题!!!
各位帮忙看看,为什么有时侯输入0-7的数时也会显示Input Error! REINPUT!,设断点调试发现此中情况下choice的值居然都为'/n'?不知道为什么,疑惑中!
#include <stdio.h>
main()
{ char choice;
int i;
int j=1;
while(j)
{ printf("\n");
printf("\t\t\t-- SEQUENCE LIST --\n");
printf("\n\t\t\t************************************");
printf("\n\t\t\t* 1-------Initialize the seqlist *");
printf("\n\t\t\t* 2-------Insert *");
printf("\n\t\t\t* 3-------Delete *");
printf("\n\t\t\t* 4-------Seek the length of the seqlist *");
printf("\n\t\t\t* 5-------Search *");
printf("\n\t\t\t* 6-------GetfromSeqList *");
printf("\n\t\t\t* 7-------ShowSeqList *");
printf("\n\t\t\t* 0-------exit *");
printf("\n\t\t\t************************************\n");
printf("\t\t\tsearch the NUM of the menu (0--7): ");
scanf("%c",&choice);
getchar();
switch(choice)
{
case '1':
printf("\n\t\t\t Initialize the seqlist");
break;
case '2':
printf("\n\t\t\t Insert");
break;
case '3':
printf("\n\t\t\t Delete");
break;
case '4':
printf("\n\t\t\t Seek the length of the seqlist ");
break;
case '5':
printf("\n\t\t\t Search ");
break;
case '6':
printf("\n\t\t\t GetfromSeqList ");
break;
case '7':
printf("\n\t\t\t ShowSeqList ");
break;
case '0':
printf("\t\t\t END of the programe !\n");
break;
default:
printf("\n\t\t\t Input Error! REINPUT!\n");
}
}
}
搜索更多相关的解决方案:
预料
----------------解决方案--------------------------------------------------------
在输入字符前要清楚键盘缓冲
用flushall函数
----------------解决方案--------------------------------------------------------
"在输入字符前要清楚键盘缓冲
用flushall函数"
那为什么将choice类型改为int后就没有问题了呢?
----------------解决方案--------------------------------------------------------
没有错误啊!我运行的什么错误都没有
----------------解决方案--------------------------------------------------------