Why can't i compare characters like this?
thnx
Code:#include <stdio.h>
int main()
{
char c = 'X';
char c2 = 'X';
char c3 = 'X';
if ( c == c2 == c3 )
printf( "Compared successfully" );
system("PAUSE");
return 0;
}
Printable View
Why can't i compare characters like this?
thnx
Code:#include <stdio.h>
int main()
{
char c = 'X';
char c2 = 'X';
char c3 = 'X';
if ( c == c2 == c3 )
printf( "Compared successfully" );
system("PAUSE");
return 0;
}
Here's a clue
Code:int main()
{
char c = 'X';
char c2 = 'X';
int c3 = 1;//What!!!!!
if ( c == c2 == c3 )
printf( "Compared successfully" );
system("PAUSE");
return 0;
}
In your example, it will return false, according to my theory, but in my example, it'll return true. But sinze that's not the case, i don't know what's wrong with it.
I hope you can explain.
thnx
Wait, i think i got it.
When i compare this:
c == c2
if they are equal they return 1, indicating true,
when it's compared to c3 like this
c2 == c3,
it's actually comparing c3 with 1 like
c3 == 1
am i right this time?
thnx
You win the prize!
So, to do what he wants to do it would be
right?Code:
if (ch1==ch2 && ch2==ch3)
....
yea