atoi Question

10 Dec 2010

 

 

Hello,  can  someone tell me where I am going wrong with this code:-

void remotecontrol() {

        myled=!myled;
        timeout.attach(&attimeout, 0.2);  /* time out after 200ms */
        remaction=atoi(remcon);
        printf("%d\n\r",remaction);
        wait_ms(100);
    }

I send a string  printf("9631\n\r")  and am expecting remaction to have the value 9631,  but,  it always evaluates  to 0.

Confusing.

 

10 Dec 2010

BTW,  I defined remcon  like 

char remcon[6];

 

10 Dec 2010

I found my problem.  If nothing is coming in the serial port, remcon is always going to be 0!