结构体里嵌套一个结构体数组指针
typedef struct{
unsigned char x;
unsigned char y;
unsigned char mode;
char *str;
}seat_s;
typedef struct
{
seat_s *seat[3];
unsigned char a;
unsigned char b;
}MENU_s;
MENU_s Top_Mode;
请教一下怎样访问seat_s这个结构体里边的每个成员,及初始化???
#include<stdio.h> #include <stdlib.h> #include<string.h> typedef struct { unsigned char x; unsigned char y; unsigned char mode; char *str; }seat_s; typedef struct { seat_s *seat[3]; unsigned char a; unsigned char b; }MENU_s; int main() { MENU_s Top_Mode; seat_s seat; for(int i=0;i<3;i++) Top_Mode.seat[i]=malloc(sizeof(seat_s)); //假设此时seat已经赋值 memcpy(Top_Mode.seat[0],&seat,sizeof(seat_s)); //假设此时seat改变 memcpy(Top_Mode.seat[1],&seat,sizeof(seat_s)); //同上 memcpy(Top_Mode.seat[2],&seat,sizeof(seat_s)); return 0; }