When comparing one character of char array in arduino , please beware use of Single quote and Double quote !! .
Example 1 :
char dat[10];
int i;
i=0;
dat[i] = 'a';
if (dat[i] == 'a') { // this use single quote , is the right way.
Serial.print("True");
}else{
Serial.print("False");
}
Example 2 :
char dat[10];
int i;
i=0;
dat[i] = 'a';
if (dat[i] == "a") { // this use double quote , is the wrong way.
Serial.print("True");
}else{
Serial.print("False");
}
CAUTION :
from these examples , in arduino all 2 example are compiled success , but Example 2 will be give you an incorrect comparation results , that cause use of double quote " " and single quote ' ' are not the same result.

ไม่มีความคิดเห็น:
แสดงความคิดเห็น