将一个结构体拷贝到字符数组缓冲区,再读出
- #include <stdio.h>
- #include <memory.h>
- typedef struct
- {
- int cmd;
- void *param;
- }st;
- char buf[50];
- int main(int argc, char* argv[])
- {
- st st1,*st2;
- st1.cmd = 1;
- st1.param = &st1.cmd;
- memcpy(buf, &st1, sizeof(st));
- st2 = (st*)buf;
- printf("cmd:%d\n", st2->cmd);
- printf("param:%d\n", st2->param);
- return 0;
- }
