检查数组元素为 null 时出错
Error checking array element to null
这个问题可能与这个问题重复question or this question
我正在使用 C 并尝试与工作在串行通信上的设备进行通信。我正在读取一个字节并将其存储在数组中,然后检查数组元素是否为 '[=11=]'
(0x00
)。如果是 '[=11=]'
,则表示数据现在不可用。
volatile int rxFlag = 0;
volatile int index = 0;
void function() //event based function, whenever a byte is received
{
Rx[index] = ReadUSART(); //reading a byte
if(Rx[index] == '[=10=]' ) //checking if its null
{
rxFlag = 1; //raise a flag
}
index++; //increment index
}
下面是Rx的截图:
在图像中,您可以看到 Rx[0]-Rx[24]
中包含数据,但 Rx[25]
是空终止符 (0x00
),并且 rxFlag
应设置为 1 . 但它没有设置。
检查数组元素是否为 '[=11=]'
的另一种方法是什么。
您在分配 rxFlag 时输入错误。
rxFlag == 1;
应该是
rxFlag = 1;
这个问题可能与这个问题重复question or this question
我正在使用 C 并尝试与工作在串行通信上的设备进行通信。我正在读取一个字节并将其存储在数组中,然后检查数组元素是否为 '[=11=]'
(0x00
)。如果是 '[=11=]'
,则表示数据现在不可用。
volatile int rxFlag = 0;
volatile int index = 0;
void function() //event based function, whenever a byte is received
{
Rx[index] = ReadUSART(); //reading a byte
if(Rx[index] == '[=10=]' ) //checking if its null
{
rxFlag = 1; //raise a flag
}
index++; //increment index
}
下面是Rx的截图:
在图像中,您可以看到 Rx[0]-Rx[24]
中包含数据,但 Rx[25]
是空终止符 (0x00
),并且 rxFlag
应设置为 1 . 但它没有设置。
检查数组元素是否为 '[=11=]'
的另一种方法是什么。
您在分配 rxFlag 时输入错误。
rxFlag == 1;
应该是
rxFlag = 1;