下面的函数从UART读取字符并将它们放入数组中。它包含来自硬件设备的repsonse。c函数返回数组并将其与另一个数组进行比较
主要我想检查数组是否包含正确的响应。
我怎样才能得到getData()
返回一个数组,我该如何比较这个数组与correctResponse
数组?
void getData(int length){
int i;
int buffresponse[6];
for (i = 0; i < length; i++)
{
//Perform a single character read from the UART interfac
buffresponse[i] = getcharacter(UART_4);
}
buffresponse[i] = 0;
}
int main(void)
{
unsigned char correctResponse[] = { 0x56, 0x00, 0x26, 0x00 };
getData();
}
}
我正在开发一个单片机,不能使用'memcmp()'还有另外一种方法吗? – transcend
@transcend,一个比较每个字节的循环? –