c - Check the value of character variable -


i'm writing code arduino , i'm not sure if i'm checking value of character variable correctly. can please tell me if correct:

const char* front = "front"; const char* = "back";  eyeballs(front); eyeballs(back);  void eyeballs(const char* frontorback){   if (frontorback == "front") {     digitalwrite(fronteyes, low);}//end if      else if (frontorback == "back") {     digitalwrite(backeyes, low);}//end else*/ }   

you need use strcmp() compare c-strings. pointer comparison.

if ( strcmp(frontorback, "front") == 0 ) {    digitalwrite(fronteyes, low);}//end if      else if ( strcmp(frontorback, "back") == 0 ) {     digitalwrite(backeyes, low);}//end else*/ }   

in comparison,

if (frontorback == "front") { 

the pointer value frontorback compared address of string literal "front" (in expression, string literal gets converted pointer first element).


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -