感觉两个程序是一样的,前者可以运行而后者不可以,求解释!
#include "stdio.h" main()
{
char i;
printf("please input the first letter of someday\n");
while ((i=getchar())!='\n')
{
switch(i)
{
case 'm':printf("1");
break;
case 'w':printf("3");
break;
case 'f' :printf("5");
break;
case't': printf("next\n");
if((i=getchar())=='u')
printf("2");
else if((i=getchar())=='h')
printf("4");
else
printf("error");
break;
case's': printf("next\n");
if((i=getchar())=='a')
printf("6");
else if((i=getchar())=='u')
printf("7");
else
printf("error");
break;
default:
printf("error");
}
}
}
#include "stdio.h"
main()
{
char i;
printf("please input the first letter of someday\n");
while((i=getch())!='\n')
{
switch (i)
{
case 's':printf("next\n");
if((i=getch())=='a')
printf("6\n");
else if ((i=getch())=='u')
printf("7\n");
else printf("data error\n");
break;
case 'f':printf("5\n");break;
case 'm':printf("1\n");break;
case 't':printf("next\n");
if((i=getch())=='u')
printf("2\n");
else if ((i=getch())=='h')
printf("4\n");
else printf("data error\n");
break;
case 'w':printf("3\n");break;
default: printf("data error\n");
}
}
}