Pages: [1]   Go Down
Author Topic: Pointer is not getting compared correctly  (Read 207 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I pass Commands to Ardiuno via serial, The format which is being used is PARM1/PARM2/PARM3 which is split by ardiuno into 3 parameters (this part is done correctly)

Even if i pass the following command STW/LED/1 or WL/0/0, it still returns command incorrect.

Code:
void setup() {
Serial.begin(9600);
Serial.flush();
}

void loop () {
char cmd[15];
int i=0;

if (Serial.available()>0) {
  for (i=0;i<15;i++) {
    cmd[i]=Serial.read();
    cmd[i+1]='\0';
    delay(50);
  }

  char* fxn=strtok(cmd,"/\0");
 
  char* obj=strtok(NULL,"/\0");
  int state=atoi(strtok(NULL,"/\0"));
 

 
  if (fxn=="STW") {
  Serial.println("STW");
  }
  else if (fxn=="WL") {
  Serial.println("WL");
  }
  else
  {
  Serial.println("Invalid Command");
  }
 
}




}
Logged

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

Code:
if (fxn=="STW") {
Did you mean
Code:
if (strcmp (fxn,"STW") == 0) {
perhaps?


(Edit: The pointers are being compared correctly, and because they cannot be the same, the comparison returns false)
« Last Edit: March 27, 2013, 06:40:11 am 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.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot!! it worked with
Code:
strcmp (fxn,"STW") == 0
Logged

Pages: [1]   Go Up
Jump to: