标签:字符串 结构体 time 关于 class 博客 div argc psi
/************************************************************************* > File Name: memtest.c > Author: > Mail: > Created Time: Thu 27 Dec 2018 05:47:37 PM CST ************************************************************************/ #include<stdio.h> #define N 50 #define IPSIZE 15 struct ClientInfo{ char headName[N]; char name[N]; int num; char ip[IPSIZE]; }; int main(int argc,char **argv) { struct ClientInfo aaa; strcpy(aaa.headName,"aaaaaaaaaaaaa"); strcpy(aaa.name,"bbbbbbbbb"); aaa.num = 10; strcpy(aaa.ip,"ccccccc"); char buf[200]; memcpy(buf,&aaa,sizeof(aaa)); struct ClientInfo bbb; memcpy(&bbb,buf,sizeof(bbb)); printf("%s\n",bbb.headName); printf("%s\n",bbb.name); printf("%d\n",bbb.num); printf("%s\n",bbb.ip); }
输出结果:
aaaaaaaaaaaaa
bbbbbbbbb
10
ccccccc
这里要注意结构体的字节对齐规则
后续会把相关知识录入博客
标签:字符串 结构体 time 关于 class 博客 div argc psi
原文地址:https://www.cnblogs.com/wzqstudy/p/10189739.html