In C I want to check if variable equal to multiple values and I don't know how to code it without separating it fully.
if (str[i]=='u'||'o'||'i'||'e'||'a') giving me always true and I don't understand why, I need explanation.
if (str[i]==('u'||'o'||'i'||'e'||'a')) giving me always false and I don't understand why, I need explanation.
thanks.
The reason why the following expression is always returning true:
if (str[i] == 'u'||'o'||'i'||'e'||'a')
is that character constants evaluate to true. So, the above is really the same as this:
if (str[i] == 'u'|| 1 || 1 || 1 || 1)
What you intended to do is this:
if (str[i] == 'u' || str[i] == 'o' || str[i] == 'i' || str[i] == 'e' || str[i] == 'a')
Note that the equality expression needs to be repeated for each comparison.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With