In my code below, a is an character array and my if statement is checking whether a particular character is A,D,O,Q,R or P.
The conventional way of checking condition in if condition is as shown in code below.
/Code Snippet/
scanf("%s",a);
len=strlen(a);
for(i=0;i<len;i++)
{
if(a[i]=='A'||a[i]=='D'||a[i]=='O'||a[i]=='Q'||a[i]=='R'||a[i]=='P')
//Do something
}
My Doubt:
1) Let' say I write if statement like this :
if(a[i]=='A'||'D'||'O'||'Q'||'R'||'P')
Why doesn't it behave in the same way as my if statement behaved in above code snippet? How does this statement work?
2) What if I want to check multiple condition(lets say hundreds or thousands of them), how can I check using just one equality operator and don't have to use multiple equality operator like this :
if(a[i]=='A'||a[i]=='D'||a[i]=='O'||a[i]=='Q'||a[i]=='R'||a[i]=='P')
Can it be done? If yes,How? If not,why?
switchstatement.strchrfrom<string.h>:if (strchr("aeiou", c)) puts("Vowel!");