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.
any ideas on going wrong??
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.
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.
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
Post a Comment