Shop OBEX P1 Docs P2 Docs Learn Events
problem with IF statement — Parallax Forums

problem with IF statement

sdiguanasdiguana Posts: 11
edited 2014-02-04 07:07 in Propeller 1
So, im not sure why this doesnt work... any ideas? I have tried (if response ==0), ..=="0",.. !=0 or "0" and so on, the only time i step into the if statement is when i set !=, but then it goes off regardless of the Xbee's status.

Snippet:
while(1) {
     pause(1000);
     xbcmd("ATMY\r", response, 15, 200);                 // showing the XBee's IP-address
     print("IP Address = %s", response); 
 

     print("cmd = ATAI\n");                            // showing 0 if the connection was successful
     xbcmd("ATAI\r", response, 10, 20);                // shows FF when scanning for a connection
     print("reply = %s", response); 
     print(response);
     if (response != "FF")
     {
       print("entered IF Statement");
       break;
     }
 }

Comments

  • mindrobotsmindrobots Posts: 6,506
    edited 2014-02-04 07:07
    sdiguana wrote: »
    So, im not sure why this doesnt work... any ideas? I have tried (if response ==0), ..=="0",.. !=0 or "0" and so on, the only time i step into the if statement is when i set !=, but then it goes off regardless of the Xbee's status.

    Snippet:
    while(1) {
         pause(1000);
         xbcmd("ATMY\r", response, 15, 200);                 // showing the XBee's IP-address
         print("IP Address = %s", response); 
     
    
         print("cmd = ATAI\n");                            // showing 0 if the connection was successful
         xbcmd("ATAI\r", response, 10, 20);                // shows FF when scanning for a connection
         print("reply = %s", response); 
         print(response);
         if (response != "FF")
         {
           print("entered IF Statement");
           break;
         }
     }
    
    

    It's standard C. You can't use relational operators to compare strings. Even StackOverflow says so. The relations operators work on the standard (sorry, not the word I want) variable types: int, char, bool, float, etc.

    You need to use strcmp to compare strings in C.
Sign In or Register to comment.