Reputation: 152
I have serial data I want to compare a specific byte to the letter "G".
LPtype is a byte that was read from the serial port.
if (LPtype == "G")
{
doThis();
}
I get the following error:
C++ forbids comparison between pointer and integer
What would be the proper way of comparing the incoming bye to the letter G? (or any other letter for that matter)
Upvotes: 3
Views: 2466
Reputation: 132994
LPtype == 'G'
Singular quotes. But LP usually prefixes pointer types, in which case you should dereference it
*LPtype == 'G'
But if you're sure LPtype is indeed a byte value, then
LPtype == 'G'
should work. The thing is that "G"
has type const char[2]
, and is not an integer type, whereas 'G'
has type char
and is integer type
Upvotes: 7