#include <ctype.h>
#include <stdio.h>
#include <string.h>
int vowel_count(char my_sen[])
{
int wcount = 0; // number of words with 3+ vowel chars
int vcount = 0; // current number of vowel chars in the current word
int i = 0; // index into the string
int ch;
while ((ch = my_sen[i++]) != '\0')
{
{
// ch is not an alphabetical char, which can happen either
// before a word or after a word.
// If it's after a word, the running vowel count can be >= 3
// and we need to count this word in.
wcount += vcount >= 3; // add 1 to wcount if vcount >= 3
vcount = 0; // reset the running vowel counter
continue; // skip spaces and non-alphabetical chars
}
if (strchr("aeiouAEIOU", ch
) != NULL
) // if ch is one of these {
++vcount; // count vowels
}
}
// If my_sen[] ends with an alphabetical char,
// which belongs to the last word, we haven't yet
// had a chance to process its vcount. We only
// do that in the above code when seeing a non-
// alphabetical char following a word, but the
// loop body doesn't execute for the final ch='\0'.
wcount += vcount >= 3; // add 1 to wcount if vcount >= 3
return wcount;
}
int main(void)
{
char sen[] = "CONSTITUTION: We the People of the United States...";
printf("# of words with 3+ vowels in \"%s\" is %d", sen
, vowel_count
(sen
)); return 0;
}
I2luY2x1ZGUgPGN0eXBlLmg+CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CgppbnQgdm93ZWxfY291bnQoY2hhciBteV9zZW5bXSkKewogIGludCB3Y291bnQgPSAwOyAvLyBudW1iZXIgb2Ygd29yZHMgd2l0aCAzKyB2b3dlbCBjaGFycwogIGludCB2Y291bnQgPSAwOyAvLyBjdXJyZW50IG51bWJlciBvZiB2b3dlbCBjaGFycyBpbiB0aGUgY3VycmVudCB3b3JkCiAgaW50IGkgPSAwOyAvLyBpbmRleCBpbnRvIHRoZSBzdHJpbmcKICBpbnQgY2g7CiAgd2hpbGUgKChjaCA9IG15X3NlbltpKytdKSAhPSAnXDAnKQogIHsKICAgIGlmIChpc3NwYWNlKGNoKSB8fCAhaXNhbHBoYShjaCkpCiAgICB7CiAgICAgIC8vIGNoIGlzIG5vdCBhbiBhbHBoYWJldGljYWwgY2hhciwgd2hp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