your code works fine, now all you have to do is check for vowels (because they are less than consonants in the alphabet). I'd have done it like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//...
for(int i = 0; str[i]; i++)
{
str[i] = tolower(str[i]); //everything to lower, to avoid checking for upper letters***
switch(str[i]) //more efficient than if-else ladder
{
case'a': str[i] = toupper(str[i]); break;
case'e': str[i] = toupper(str[i]); break;
case'i': str[i] = toupper(str[i]); break;
case'o': str[i] = toupper(str[i]); break;
case'u': str[i] = toupper(str[i]); break;
//i passed the 'y' - is it a vowel or consonant in english alphabet? :-)
default: str[i] = tolower(str[i]); break;
}
}
//...
//*** - IMO this code a bit slower if i didn't check for upper letters, that's only my laziness
Or put all that in a single statement using the conditional operator: str[i] = ( str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' ) ? toupper(str[i]) : tolower(str[i]);