码迷,mamicode.com
首页 > 其他好文 > 详细

7.11 animals.c 程序

时间:2019-04-13 21:38:46      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:输入   ima   void   only   als   animal   程序   beginning   isl   

7.11 animals.c 程序

#include <stdio.h>
#include <ctype.h>
int main(void)
{
    char ch;
    printf("Give me a letter of the alphabet, and I will give ");
    printf("an animal name\nbeginning 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, a wild sheep of Asia\n");
                   break;
            case 'b':
                   printf("babirusa, 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");
        }            /*  switch 结束   */
        else 
            printf("I recognize only lowercase letters.\n");
        while (getchar() != '\n')
            continue;    /* 跳过输入行的剩余部分 */
        printf("Please type another letter or a #.\n");
    }                     /*  while循环结束  */
    printf("Bye!\n");
    return 0;
}

7.11 animals.c 程序

标签:输入   ima   void   only   als   animal   程序   beginning   isl   

原文地址:https://www.cnblogs.com/EisNULL/p/10702906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!