starsrch.c 568 B

1234567891011121314151617181920212223242526
  1. /* starsrch.c -- use strncmp() */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #define LISTSIZE 6
  5. int main()
  6. {
  7. const char * list[LISTSIZE] =
  8. {
  9. "astronomy", "astounding",
  10. "astrophysics", "ostracize",
  11. "asterism", "astrophobia"
  12. };
  13. int count = 0;
  14. int i;
  15. for (i = 0; i < LISTSIZE; i++)
  16. if (strncmp(list[i],"astro", 5) == 0)
  17. {
  18. printf("Found: %s\n", list[i]);
  19. count++;
  20. }
  21. printf("The list contained %d words beginning"
  22. " with astro.\n", count);
  23. return 0;
  24. }