Stegosaurus Stegosaurus - 1 year ago 82
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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download