#include <stdio.h>
#include <string.h>
/* main: main loop for counting vowels in word */
int main(void)
{
size_t i, j, word_len, vowels_len;
int vowel_count;
char word[21]; /* 20 + '\0' */
static const char vowels[] = "aeiouAEIOU";
printf("Enter a word: ");
scanf("%20s", word);
/* initialise variables */
word_len = strlen(word);
vowels_len = strlen(vowels);
vowel_count = 0;
for (i = 0; i < word_len; ++i) { /* loop through word */
for (j = 0; j < vowels_len; ++j) { /* loop through vowels */
if (word[i] == vowels[j]) {
++vowel_count;
break;
}
}
}
printf("\nThe no. of vowels in '%s' is %d\n", word, vowel_count);
/* indicate success */
return 0;
}