1
0

animals.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* animals.c -- uses a switch statement */
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. int main(void)
  5. {
  6. char ch;
  7. printf("Give me a letter of the alphabet, and I will give ");
  8. printf("an animal name\nbeginning with that letter.\n");
  9. printf("Please type in a letter; type # to end my act.\n");
  10. while ((ch = getchar()) != '#')
  11. {
  12. if('\n' == ch)
  13. continue;
  14. if (islower(ch)) /* lowercase only */
  15. switch (ch)
  16. {
  17. case 'a' :
  18. printf("argali, a wild sheep of Asia\n");
  19. break;
  20. case 'b' :
  21. printf("babirusa, a wild pig of Malay\n");
  22. break;
  23. case 'c' :
  24. printf("coati, racoonlike mammal\n");
  25. break;
  26. case 'd' :
  27. printf("desman, aquatic, molelike critter\n");
  28. break;
  29. case 'e' :
  30. printf("echidna, the spiny anteater\n");
  31. break;
  32. case 'f' :
  33. printf("fisher, brownish marten\n");
  34. break;
  35. default :
  36. printf("That's a stumper!\n");
  37. } /* end of switch */
  38. else
  39. printf("I recognize only lowercase letters.\n");
  40. while (getchar() != '\n')
  41. continue; /* skip rest of input line */
  42. printf("Please type another letter or a #.\n");
  43. } /* while loop end */
  44. printf("Bye!\n");
  45. return 0;
  46. }