我的程序是從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