Pages: [1]   Go Down
Author Topic: comparing character  (Read 2272 times)
0 Members and 1 Guest are viewing this topic.
Bern, Switzerland
Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if (((char*)GPS.arguments[2]) == "A")
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"A" is a string.
'A' is a character.
Logged

"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.

Bern, Switzerland
Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

How must I write it?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"char*" is a pointer, so

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

should do the trick.
Logged

"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.

Bern, Switzerland
Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Error message is still the same....
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, if you actually told us what a "GPS" looked like, we could dispense with the banter.
Logged

"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.

Bern, Switzerland
Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps I found a possibility with this code:
Code:
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 :-)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: October 18, 2010, 03:43:44 pm by AWOL » Logged

"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.

Bern, Switzerland
Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's a libelium gps module ...brrrr
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not the module, the variable.    >smiley-sad
Logged

"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.

Bern, Switzerland
Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Show us the C declaration of the "GPS" variable (as in "GPS.arguments[2]") from your sketch, my psychic powers are failing.
Please.
Logged

"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.

Pages: [1]   Go Up
Jump to: