Stegosaurus Stegosaurus - 2 months ago 11
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
[-Wconstant-logical-operand]


why is this happening?

Answer

What you meant to say was:

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

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