C - IF(char[] == "ZYX") 不起作用 [英] C - IF(char[] == "ZYX") don't work
本文介绍了C - IF(char[] == "ZYX") 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 arduino 发送到 arduino 字符串 (I2C),捕获并保存到 char[10].当我将此变量与文本进行比较时,条件没有执行 :-/而且我不知道为什么...
I send from arduino to arduino string (I2C), catch and save to char[10]. When I compare this variable to text, condition don't have execute :-/ And I don't know why...
char dataRx[10] = "";
void DaemonReceiving(int howMany){
int index = 0;
while(Wire.available() > 0){
char c = Wire.read();
dataRx[index++] = c;
dataRx[index] = '\0';
}
Serial.println(dataRx);
if(dataRx == "HELLO"){
Wire.beginTransmission(1);
Wire.write("HI");
Wire.endTransmission();
}
}
推荐答案
要将 dataRX 字符串与HELLO"进行比较,请使用:
To compare the dataRX string to "HELLO", use:
if (strcmp (dataRx,"HELLO") == 0) {
// matches HELLO
}
这篇关于C - IF(char[] == "ZYX") 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文