- 论坛徽章:
- 0
|
感觉楼主有些概念没搞清
不知道下面这段代码能否让楼主搞清一些概念
- #include <stdio.h>
- struct aa
- {
- char morepkt;
- char pktype;
- char unitend;
- char save;
- short sequence;
- short length;
- long msgtype;
- };
- int main(void)
- {
- struct aa val;
- char str[256];
- memset(&val, 0x00, sizeof(struct aa));
- memset(str,0x00,sizeof(str));
- // sprintf(str, "%s", "12345678 999");
- str[0] = 'a';
- str[1] = 'b';
- str[2] = 'c';
- str[3] = 'd';
- str[4] = (short)0x0102;
- str[6] = (short)0x0304;
- str[8] = (long)0x05060708;
- memcpy(&val, str, sizeof(struct aa));
- printf("[%d]\n", val.sequence);
- }
复制代码 |
|