Count vowels and consonants in a string.
#include <ctype.h>
void count_vc(const char *s, int *vowels, int *consonants)
{
*vowels = *consonants = 0;
for (; *s; s++) {
int c = tolower((unsigned char)*s);
if (c < 'a' || c > 'z') continue; /* skip digits, spaces, punctuation */
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') (*vowels)++;
else (*consonants)++;
}
}
/* "Hello World" -> vowels 3, consonants 7 */
Points: ignore non-letters; handle upper case; cast to unsigned char before tolower.