Go Down

Topic: comparing character (Read 2591 times) previous topic - next topic

schwizer

Hi
I have a problem to with comparing two characters.

When I compare a char which is read from gps, with my char A, the solution of this compair is evertime false.
If the char red from gps is really A, the compare is still false.....
How can I find out if there is a A in ((char*)GPS.arguments[2])?

Code: [Select]
if (((char*)GPS.arguments[2]) == "A")

AWOL

"A" is a string.
'A' is a character.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

schwizer

The corrected code throws an error:
ISO C++ forbids comparison between pointer and integer
Code: [Select]
if (((char*)GPS.arguments[2]) == 'A')

How must I write it?

AWOL

"char*" is a pointer, so

if (GPS.arguments[2] == 'A')

should do the trick.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

schwizer

Error message is still the same....

AWOL

Well, if you actually told us what a "GPS" looked like, we could dispense with the banter.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

schwizer

Perhaps I found a possibility with this code:
Code: [Select]
char* A = {"A"};
 if ((char*)GPS.arguments[2] == (char*)A[0])


But I have to go outdoor and wait until gps is set up (A is only printed if data is valid). It's cold outdoor, but I have to try it :-)

AWOL

#7
Oct 18, 2010, 10:43 pm Last Edit: Oct 18, 2010, 10:43 pm by AWOL Reason: 1
Well, if you actually told us what a "GPS" looked like, we could dispense with the banter, and you don't have to suffer any discomfort.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

schwizer

It's a libelium gps module ...brrrr

AWOL

Not the module, the variable.    >:(
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

schwizer

Sorry, I don't know what you are asking (my english isn't good enough).

The variable who the gps is writing in the array can be a A or a V.
When the pointer  shows on position 2 in the array like: GPS.arguments[2], it should return the character A or V....

So I thought that I can compare this character with another char.

AWOL

Show us the C declaration of the "GPS" variable (as in "GPS.arguments[2]") from your sketch, my psychic powers are failing.
Please.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up