Counting vowels

This is a discussion on Counting vowels within the C Programming forums, part of the General Programming Boards category; [Prompt the user to enter a sentence, then hit newline. Read the sentence one character at a time, until you ...

If you're trying to read a string, you should use "%s" here, and eliminate the '&' before "sentence" (as "sentence" alone will act like a pointer to the first element of that array).

Be warned, however, that "scanf()" will stop reading when it hits whitespace (such as a space or a tab), so entering a sentence will be difficult. (There are ways around it, but let's not worry about that now.)

Perhaps you were intending to enter one one character at a time using "%c"? In that case, you'd need the "scanf()" in a loop, and to include the (incrementing) index number in the second argument (i.e. "&sentence[i]").

Code:

if (sentence[loop] = 'a'||'e'||'i'||'u')

This is incorrect syntax.

First of all, you want the comparison operator ( == ), not the assignment operator ( = ).

Secondly, you need to explicitly compare the input with each possible character, i.e.

Code:

if(sentence[loop] == 'a' || sentence[loop] == 'e' || ... )

You also want to use "%d" to print out an integer. %c will print out a character.

Have you tested it? The results are dreadfully wrong. There are dangers to simply copy+pasting code and not understanding. The code I provided was intended to illustrate a concept, not to be shoved into the program without thought.

Yeah, sorry about the mess... just trying to fit it all together before I make it neat.
yes, i tried it w/o the scanf() and it reads properly...
now im trying to input another sample sentence after the first.... but the "Press any key to continue..." comes up...
I tried...
system("pause")
printf("Sample sentence #2");

I also input a sentence but do not receive a proper output:
This is a Sentence.
SAMPLE OUTPUT, for EACH sentence above:
Program#5 CS110.
Keystrokes 1
Alpha Characters 0
Vowels 0
Press any key to continue . . .