初始化struct指针

foo*_*o_l 3 c struct initialization

typedef struct
{
  char *s;
  char d;
}EXE;
EXE  *p;
Run Code Online (Sandbox Code Playgroud)

对于上面struct我如何用指针初始化结构?我知道我们做的非指针EXE a[] = { {"abc",1}, {"def",2} };.同样在分配内存后是否可以使用指针?说得像p[] = { {"abc",1},.. so on}.基本上我想动态初始化.谢谢.

Ent*_*KEY 7

我们可以用指针初始化结构,如下所示

example:
 int i;
 char e[5]="abcd";
 EXE *p=malloc(sizeof(*p));
 for(i = 0;i < 5;i++)
   *(p+i)=(EXE){e,i+48};
Run Code Online (Sandbox Code Playgroud)