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

sql - VB.NET Operand type clash: date is incompatible with int error -

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

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -