struct char* 使用

 1 typedef struct people{
 2     char* name;
 3     int age;
 4 }PEO;
 5 
 6 void structdemo(){
 7    PEO* peo_0 = malloc(sizeof(PEO));
 8    peo_0->age = 20;
 9    peo_0->name = malloc(sizeof(char)*20);
10    peo_0->name = "jia";
11    free(peo_0); free(peo_0->name);
12 }

char* name or char name[20]

if not 

  peo_0->name = malloc(sizeof(char)*20);
fault
posted @ 2019-01-10 16:34  zjhangia  阅读(522)  评论(0编辑  收藏  举报