String Comparison


so trying create function update status text on lcd, , store current value has written updates on change of status, reason "currentstatus" blank...  here code.

code: [select]

char status[40];
char currentstatus[40];

       /* update status on lcd */
       char* status = "hello...";
         
         serial.println(status);
         serial.println(currentstatus);
       
         if(currentstatus != status) {
           updatestatus(status);
           char* currentstatus = status;
         }


any ideas on going wrong??

the value "status" never equal "currentstatus" because both separately defined arrays.

the name of array same address of array's first element.  the name of array used pointer first element.  the addresses don't move when contents of arrays change.  you're comparing addresses.

if want see if contents identical first 0 character (the terminator), see strcmp( ) routine.

code: [select]
if (0 == strcmp(status, currentstatus)) { ... }

anyone wants learn how pointers work should consider assignment homework:  implement strlen(), strcpy(), strcmp(), strcat() , strchr().  the basic implementations extremely easy , compact , elegant, elegant v = r i.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > String Comparison


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums