Advertisement
dmkozyrev

count.c

Jan 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void count(const char *str, int *counts)
  5. {
  6.     char alp[] = "aeiouy";
  7.     int i, len = strlen(alp);
  8.     for (i = 0; i < len; counts[i++] = 0);
  9.  
  10.     char *pos;
  11.     while (*str != '\0')
  12.     {
  13.         if ((pos = strchr(alp, *str)) != 0)
  14.             counts[pos - alp]++;
  15.         str++;
  16.     }
  17. }
  18.  
  19. int main()
  20. {
  21.     unsigned const int N = 6;
  22.     int counts[N] = { };
  23.     char str[] = "Happy birthday, Denis Vasilyevich!";
  24.     printf("str = %s\n", str);
  25.     count(str, counts);
  26.     char alp[] = "aeiouy", *p;
  27.     for (p = alp; *p != '\0'; p++)
  28.         printf("%c = %d ", *p, counts[p - alp]);
  29.     printf("\n" );
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement