Ç - IF(的char [] ==" ZYX")不工作 [英] C - IF(char[] == "ZYX") don't work

查看:238
本文介绍了Ç - IF(的char [] ==" ZYX")不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从阿尔杜伊诺发送到Arduino的字符串(I2C),捕捉并保存为char [10]。当我比较该变量为文本,条件不具备执行: - /我不知道为什么...

 字符dataRx [10] =;无效DaemonReceiving(INT的howmany){
  INT索引= 0;  而(Wire.available()大于0){
    焦C = Wire.read();    dataRx [指数++] = C;
    dataRx [指数] ='\\ 0';
  }
  Serial.println(dataRx);  如果(dataRx ==HELLO){
        Wire.beginTransmission(1);
        Wire.write(HI);
        Wire.endTransmission();
  }
}


解决方案

要比较dataRX字符串为Hello,使用:

 如果(STRCMP(dataRx,HELLO)== 0){    //匹配HELLO}

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();
  }
}

解决方案

To compare the dataRX string to "HELLO", use:

if (strcmp (dataRx,"HELLO") == 0) {

    // matches HELLO

}

这篇关于Ç - IF(的char [] ==" ZYX")不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆