7.11 animals.c 程序

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
beginning with that letter.
");
    printf("Please type in a letter; type # to end my act.
");
    while ((ch = getchar())  != '#')
    {
        if ('
'  == ch)     // 不会担心变成赋值语句
            continue;
        if (islower(ch))     /* 只接受小写字母 */
            switch (ch)
        {
            case 'a':
                   printf("argali, a wild sheep of Asia
");
                   break;
            case 'b':
                   printf("babirusa, a wild pig of Malay
");
                   break;
            case 'c':
                   printf("coati, racoonlike mammal
");
                   break;
            case 'd':
                   printf("desman, aquatic, molelike critter
");
                   break;
            case 'e':
                   printf("echidna, the spiny anteater
");
                   break;
            case 'f':
                   printf("fisher, brownish marten
");
                   break;
            default:
                   printf("That's a stumper!
");
        }            /*  switch 结束   */
        else 
            printf("I recognize only lowercase letters.
");
        while (getchar() != '
')
            continue;    /* 跳过输入行的剩余部分 */
        printf("Please type another letter or a #.
");
    }                     /*  while循环结束  */
    printf("Bye!
");
    return 0;
}
原文地址:https://www.cnblogs.com/EisNULL/p/10702906.html