有关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···呜呜呜····以后注意哦···

posted on 2013-08-23 16:36  イケメンおっさん_汪汪  阅读(553)  评论(0编辑  收藏  举报

导航