|
-
April 3rd, 2011, 08:32 PM
#1
Counting characters help
I have a program for class where I need to count the number of vowels in one function, then count consonants in another function. I got the vowel one easy. However, I'm a bit stuck on the consonant one. I have my function test if the character is a vowel or whitespace, and skip it. It counts all other characters.
Two problems - first, i used continue in my vowel/whitespace test and it's getting hung up. What should I use here? Second, how can I account for punctuation? I have an array of "a, e, i, o, u" to test against for vowels... do I need to make one with all the other symbols... or is there a c-type test thing I can use to make it easier, like isalpha (I don't know how I'd use it though)? Here's my function:
Code:
int countCons(char *userString, char *vowel)
{
int count = 0;
while (*userString != '\0')
{
if (*userString != *vowel || *userString != ' ')
continue; // doesn't work
else
count++;
userString++;
}
return count;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|