Stegosaurus Stegosaurus - 11 months ago 52
C Question

comparing an input to two characters, creates odd warning

I am trying to compare an input to two different characters and execute the if condition if either of the conditions are met.

My code so far is:

if(i == 'Y'||'y') {
//code here

but the GCC compiler spits out the warning:

warning: use of logical '||' with constant operand

why is this happening?

Answer Source

What you meant to say was:

  if(i == 'Y'|| i == 'y')

The compiler is telling you exactly what you needed to know!