有关continue的小程序(1)

看一个 continue的程序

c prim plus 7.9

 1 #include<stdio.h>
 2 #include<ctype.h>
 3 int main(void)
 4 {    char ch;
 5     printf("        You give me a letter,\n        and I give you a word;\n"
 6            "        Input  a # to quit\n");
 7     while((ch=getchar())!='#')
 8     {
 9         if('\n' == ch) continue; //处理刚开始输入的换行符 
10         
11         if(islower(ch))
12             switch(ch)
13             {
14                 case 'a': printf("apple\n"); break;
15                 case 'b': printf("basketball\n"); break;
16                 case 'c': printf("cell\n"); break;
17                 case 'd': printf("desirable\n"); break;
18                 case 'e': printf("elements\n"); break;
19                 case 'f' :printf("fisher, brownish marten\n");break;
20                 default: printf("this is a beautiful world!\n"); break;
21             }
22         else
23             printf("Input a lowercase letter.\n");
24     
25     /*读取并丢弃输入,直至一行的末尾*/
26     while( getchar()!='\n') continue; //跳过输入行的剩余部分 
27         
28         printf("Input another letter\n");
29         printf("----------------------\n");        
30             
31     }
32     printf("Bye····\n"); 
33     return 0;
34 }

实验结果如下:

范的错误,我第9行 

if('\n' == ch) continue;   刚开始写为了 if('\n' == getchar()) continue; 这样呢,比如输入 两个字符,才能进入switch···呜呜呜····以后注意哦···

转载于:https://www.cnblogs.com/kalo1111/p/3277805.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值