charget_choice(void)
{
charch;
intsel=-1;
printf("請選擇您要進行的操作:\n"
"A.加B.減\n"
"C.乘D.除\n"
"E.退出\n");
while(1)
ch=getchar();
if(sel==-1)
if(!(ch=="\n"||ch==""))
sel=ch;
}
else
if(ch=="\n")
if(sel>="A"&&sel<="E")break;
printf("請輸入:A,B,C,D或E:");
sel=-1;
returnsel;
輸入空格T回車,出現提示“請輸入:A,B,C,D或E:”
輸入空格A空格回車,返回"A"
按照你的意思做的。
charget_choice(void)
{
charch;
intsel=-1;
printf("請選擇您要進行的操作:\n"
"A.加B.減\n"
"C.乘D.除\n"
"E.退出\n");
while(1)
{
ch=getchar();
if(sel==-1)
{
if(!(ch=="\n"||ch==""))
{
sel=ch;
}
}
else
{
if(ch=="\n")
{
if(sel>="A"&&sel<="E")break;
else
{
printf("請輸入:A,B,C,D或E:");
sel=-1;
}
}
}
}
returnsel;
}
輸入空格T回車,出現提示“請輸入:A,B,C,D或E:”
輸入空格A空格回車,返回"A"
按照你的意思做的。