I'm making a program that is supposed to count vowels. I made a char array and via if-statement I'm checking each element of it:
for( i=0 ; sent[i]!='\0' ; i++)
{
if (sent[i] = ='A'||'a'||'E'||'e'||'I'||'i'||'O'||'o'||'u')
{ vow++;
}
}
Now when I'm typing "My name is Arsal" on console, it is giving output "16 vowels" which is actually the number of all alphabetic characters along with spaces in above sentence. When I'm removing "OR(s)"
if (sent[i] = ='A' /*||'a'||'E'||'e'||'I'||'i'||'O'||'o'||'u' */)
{ vow++;
}
the program is giving the correct output of "1" in above sentence.
This is the complete program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
int vow=0;
char sent[100];
printf("Enter sentence ; \n");
gets(sent);
printf("\n");
int i,j;
for(i=0 ; sent[i]!='\0';i++)
{
if (sent[i] == 'A'||'a'||'E' || 'e' || 'O' ||'o'||'I'||'i' ||'U' ||'u')
{
vow++;
}
}
printf("\n No.of vowels = %d",vow);
getch();
}
Please tell me the reason.