Finding Number of Vowels, Consonants & Words
void countAll(char a[]) {
int vowels=0, consonants=0, words=1;
for (int i = 0; a[i] != '\0'; i++) {
if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u' || a[i] == 'A' || a[i] == 'E' || a[i] == 'I' || a[i] == 'O' || a[i] == 'U') {
vowels++;
} else if ((a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= 'a' && a[i] <= 'z')) {
consonants++;
} else if (a[i] == ' ') {
words++;
}
}
printf("Vowels: %i\tConsontants: %i\tWords: %i\n", vowels, consonants, words);
}Last updated