我有以下字节数组,我将其转换为以下结构:
**我知道"0x80",
等格式不正确,但在我的代码中却是。
unsigned char ReadBuffer[512] = { 80 00 00 00 50 00 00 00 01 00 40 00 00 00 01 00 00 00 00 00 00 00 00 00 FF F2 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 30 0F 00 00 00 00 00 00 30 0F 00 00 00 00 00 00 30 0F 00 00 00 00 33 20 C8 00 00 00 0C 42 E0 2A 0F 9F B9 00 00 FF}
typedef struct MFT_ATTRIBUTE {
DWORD dwType;
DWORD dwFullLength;
BYTE uchNonResFlag;
BYTE uchNameLength;
WORD wNameOffset;
WORD wFlags;
WORD wID;
LONG n64StartVCN;
LONG n64EndVCN;
WORD wDatarunOffset;
WORD wCompressionSize;
BYTE uchPadding[4];
LONGLONG n64AllocSize;
LONGLONG n64RealSize;
LONGLONG n64StreamSize;
} MFT_ATTRIBUTE, *P_MFT_ATTRIBUTE;
MFT_ATTRIBUTE* mft_attribute = (MFT_ATTRIBUTE*)ReadBuffer[0];
当我尝试打印成员时,由于某种原因,我得到了某种增量值:
printf("%x ",&mft_attribute->dwType);
printf("%x ",&mft_attribute->dwFullLength);
printf("%x ",&mft_attribute->uchNonResFlag);
printf("%x ",&mft_attribute->uchNameLength);
Output:
0x80 0x84 0x88 0x89
有人可以帮我澄清一下吗?
答案 0 :(得分:3)
您正在打印地址,而不是值。这就是输出以这种方式增加的原因:
float distCovered = (Time.time - startTime) * speed;
float fracJourney = distCovered / journeyLength;
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
删除&在输出代码中的mft_attribute之前:
dwType
答案 1 :(得分:1)
您正在将数组的第一个元素转换为指向结构的指针。
MFT_ATTRIBUTE* mft_attribute = (MFT_ATTRIBUTE*)ReadBuffer[0];
您想要将指针强制转换为第一个元素:
MFT_ATTRIBUTE* mft_attribute = (MFT_ATTRIBUTE*) (ReadBuffer + 0);
同样正如@Wolf指出的那样打印指针而不是指向的值:
printf("%x ",&mft_attribute->dwType);
你需要
printf("%x ", mft_attribute->dwType);
答案 2 :(得分:0)
将演员表更改为以下内容:
MFT_ATTRIBUTE* mft_attribute = (MFT_ATTRIBUTE*)&ReadBuffer[0];
或
MFT_ATTRIBUTE* mft_attribute = (MFT_ATTRIBUTE*)ReadBuffer;