home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / falcon / program / x_debug / tutorial / vowels.c < prev    next >
C/C++ Source or Header  |  1993-01-02  |  1KB  |  66 lines

  1.  
  2. /* program to accompany X-Debug tutorial */
  3.  
  4. /* program searches a word list for vowels, but doesn't quite work */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. char *find_string[] = {
  11.     "first",
  12.     "second",
  13.     "third",
  14.     NULL
  15.     };
  16.  
  17. /* count how many of a particular character are in a string */
  18.  
  19. int count_char(char *string, char c)
  20. {
  21. int count = 0;
  22.  
  23.     for (;;)
  24.         {
  25.         string = strchr(string, c);
  26.         if (string==NULL)
  27.             return count;                    // stop if no more
  28.         count++;                            // else increase count
  29.         string++;                            // and inc pointer to next char
  30.         }
  31. }
  32.  
  33. /* count how many vowels are in a particualr string */
  34.  
  35. int count_vowels(char *string)
  36. {
  37. int count;
  38.  
  39.     count  = count_char(string, 'a');
  40.     count += count_char(string, 'e');
  41.     count += count_char(string, 'i');
  42.     count += count_char(string, 'o');
  43.     count += count_char(string, 'u');
  44.  
  45.     return count;
  46. }
  47.  
  48. int main(int argc, char *argv[])
  49. {
  50. char **which;
  51. char *p;
  52.  
  53.     which = find_string;
  54.     do
  55.         {
  56.         int c;
  57.         
  58.         p = *which++;
  59.         c = count_vowels(p);
  60.         printf("%s:%d\n", p, c);
  61.         }    
  62.     while (p);
  63.  
  64.     return 0;
  65. }
  66.