如何正确比较两个未签名的字符?

T.T*_*.T. 1 c c++ windows networking char

期待比较两个

BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH];
Run Code Online (Sandbox Code Playgroud)

来自IP_ADAPTER_ADDRESSES结构

其中byte在windows中定义为 typedef unsigned char BYTE;

我需要比较记忆吗?

谢谢!

Mat*_*lia 6

注意:PhysicalAddress正如文档中所解释的那样,定义是

  BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH];
Run Code Online (Sandbox Code Playgroud)

也就是说,它是一个数组BYTE秒.不过,你可以用轻松地比较他们memcmp<string.h>(或者<cstring>,如果你是用C++):

// The two structures
IP_ADAPTER_ADDRESSES iaa1, iaa2;
// The result of the comparison
int result;

//...

if(iaa1.PhysicalAddressLength!=iaa2.PhysicalAddressLength)
{
    // We have two physical addresses of two different lengths; depending on what
    // you want to do it may be an error or just a simpler case of comparison
}
else
{
    // Perform the comparison
    result = memcmp(iaa1.PhysicalAddress, iaa2.PhysicalAddress, iaa1.PhysicalAddressLength);
}
Run Code Online (Sandbox Code Playgroud)