Counting vowels function

This function is supposed to take a sentence the user enters and add up the vowels within this sentence and return the number of vowels. Right now the function simply returns the total number of characters in the string and not the vowels. What am i doing wrong? Thanks

1
2
3
4
5
6
7
8
9
10
11
  int vowelCount(char* strPtr)
{
    int count=0;
    while(*strPtr!= '\0')
    {
        if (*strPtr=='a'||'e'||'i'||'o'||'u')
            count++;
        strPtr++;
    }
return count;
}
if (*strPtr=='a'||'e'||'i'||'o'||'u')
This doesn't do what you think it does.

The condition is true if *strPtr is 'a', or if true or if true or if true or if true.
Let me explain.

Since you aren't comparing 'e', 'i', 'o', 'u' to anything (you may think you are, but you're not), and since those ascii characters converted to decimal are non-zero values, they all evaluate to true.

You need to be explicit.
if(*strPtr=='a' || *strPtr=='e'/*etc...*/)
awesome, I get what you're saying. thanks for the help, i knew it wasn't a hard fix.
Topic archived. No new replies allowed.