请教一个通过数组给结构体赋值的方法
1个回答
展开全部
#include <string.h>
#include <stdio.h>
int main()
{
struct HEAD{
char id[4];
char type[1];
char name[10];
}head;
char ss[50] = "11113mike";
memcpy(&head,ss,sizeof(head));
printf("%.*s\n%.*s\n%.*s\n", sizeof( head.id), head.id, sizeof( head.type),head.type, sizeof( head.name), head.name);
}
#include <stdio.h>
int main()
{
struct HEAD{
char id[4];
char type[1];
char name[10];
}head;
char ss[50] = "11113mike";
memcpy(&head,ss,sizeof(head));
printf("%.*s\n%.*s\n%.*s\n", sizeof( head.id), head.id, sizeof( head.type),head.type, sizeof( head.name), head.name);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询