我的程序是从Zigbee接收数据并对其进行过滤以得到我想要的数据。如何将字符数组与字符串进行比较
unsigned char idata buff[100]; //To read data from rawrxd[] and process data
unsigned char count=0; //To store counter for rawrxd[]
unsigned char buff_count=0; //store counter for buff[], read counter for rawrxd[]
if(buff_count!=count) //checking Is there any unread data?
{
if(buff_count==100) //go back to start position of array
buff_count=0;
buff[buff_count] = rawrxd[buff_count]; //read the data
if(strcmp(buff, "UCAST:000D6F0000A9BBD8,[email protected]") ==0)
{
ES0=0;
Serial_txString("AT+UCAST:[email protected]");
tx(0x0D);
tx(0x0A);
ES0=1;
}
if(strcmp(buff, "UCAST:000D6F0000A9BBD8,06=!221#@") ==0)
{
ES0=0;
Serial_txString("AT+UCAST:000D6F0000A9BBD8=!222#@");
tx(0x0D);
tx(0x0A);
ES0=1;
}
buff_count++; //increase the read_count
}
这是应该的缓冲区将接收尤卡斯特,然后用它是否是相同的字符串比较它,返回0 然而,这只是一个时间进行比较之后,我收到了下一个UCAST它根本不会比较。
此外,它的第一次比较必须是相同的才能工作。如果收到错误的字符,然后收到正确的字符它不会工作。由此,这是指针问题吗?由于我的缓冲区是一个char数组,我试图将它与一个字符串进行比较。
我试过把buff [++ buff_count] ='\ 000';但它重复了很多时间意味着不断打印。另外,读取数据后呢?如果是,它根本不起作用。 – JiaYuan
@佳园:对不起。我忘了提及删除循环底部的增加'buff_count'的语句。 – wallyk