关于continue的用法疑问:
关于continue的用法疑问:
// animal.c
#include
#include
int main(void)
{
char ch;
printf(" Give me a letter of the alphabet,and i will give ");
printf(" an animal name \n beginning with that letter.\n");
printf("Please type in a letter :type # to end my act.\n");
while((ch= getchar()) = '#');
{
if('\n'==ch)
continue;
if(islower(ch))
switch(ch)
{
case 'a':
printf("argali,awild sheep of Asia\n");
break;
case 'b':
printf("bablirusa,a wild pig of Malay \n");
break;
case 'c':
printf("coati,racoonlike mammal \n");
break;
case 'd':
printf("Desman,aquatic,molelike critter \n");
break;
case 'e':
printf("echidna,the spiny anteater\n");
break;
case'f':
printf("fisher,brownish marten \n");
break;
default:
printf("That's a stumper \n");
}
else
printf("I recognize only lowercase letters.\n");
while(getchar()!='\n')
continue;
printf("Please enter another letter of a #.\n");
}
printf("Bye!\n");
return 0;
}
编译了一下,发现有问题:
错误提示是:
--------------------Configuration:animal2 - Win32 Debug--------------------
Compiling...
animal2.c
D:\我的文档\animal2.c(13) :error C2044:illegal continue
Error executing cl.exe.
animal2.obj - 1 error(s),0 warning(s)
// animal.c
#include
#include
int main(void)
{
char ch;
printf(" Give me a letter of the alphabet,and i will give ");
printf(" an animal name \n beginning with that letter.\n");
printf("Please type in a letter :type # to end my act.\n");
while((ch= getchar()) = '#');
{
if('\n'==ch)
continue;
if(islower(ch))
switch(ch)
{
case 'a':
printf("argali,awild sheep of Asia\n");
break;
case 'b':
printf("bablirusa,a wild pig of Malay \n");
break;
case 'c':
printf("coati,racoonlike mammal \n");
break;
case 'd':
printf("Desman,aquatic,molelike critter \n");
break;
case 'e':
printf("echidna,the spiny anteater\n");
break;
case'f':
printf("fisher,brownish marten \n");
break;
default:
printf("That's a stumper \n");
}
else
printf("I recognize only lowercase letters.\n");
while(getchar()!='\n')
continue;
printf("Please enter another letter of a #.\n");
}
printf("Bye!\n");
return 0;
}
编译了一下,发现有问题:
错误提示是:
--------------------Configuration:animal2 - Win32 Debug--------------------
Compiling...
animal2.c
D:\我的文档\animal2.c(13) :error C2044:illegal continue
Error executing cl.exe.
animal2.obj - 1 error(s),0 warning(s)
其他人气:391 ℃时间:2020-03-18 23:18:26
优质解答
你的while后面有个分号.后面那个大括号就不在while里了,所以continue也不再while里,continue只有在循环内才有意义,否则就会出现这种错误.
我来回答
类似推荐
猜你喜欢
- 1设3x的二次方-x=1,那么9x的三次方+9x的二次方-7x+2001
- 2Noise pollution can make people deaf.转换成People may ( )deaf( )noise pollution.括号里填什么?
- 3八年级下学期科学
- 4烧水的铝壶中常结有一层水垢(水垢的主要成分是CaCO3),用适量的稀盐酸可以除去它,反应的化学方程式是_.若盐酸的用量过多,会损坏铝壶,反应的化学方程式是_.
- 5在11*11的方格中填入1~121,使得横竖斜相加都为一个数
- 6第二课山雨,求主要内容
- 728分之19减7分之2减14分之1等于多少
- 8水果店运进一批桔子,第一天卖出全部的1/6,第二天卖了24千克,
- 9it is down from two to three hours to just 40 minutes a night
- 10"Shut up you will never understand there something has changed!