空羊羊 发表于 2020-11-15 16:03:43

代码显示segmentation fault,有没有大佬能帮忙看一下为什么

#include <stdio.h>
struct Entry{
                char *name;
                char *number;
                char *department;
};

void addnumber(struct Entry **library);

void main(void){
        struct Entry *directory=NULL;
        addnumber(&directory);
}

void addnumber(struct Entry **library){       
        (**library).name="abcde";
}

xieglt 发表于 2020-11-17 11:51:16

#include <stdio.h>
struct Entry{
                char *name;
                char *number;
                char *department;
};

void addnumber(struct Entry **library);

void main(void){
               
                //指针赋值NULL了,不能对它进行操作,应该这么写。
                //struct Entry *directory= NULL;
                struct Entry dir;
      struct Entry *directory= &dir;
      addnumber(&directory);
}

void addnumber(struct Entry **library){      
      (**library).name="abcde";
}
页: [1]
查看完整版本: 代码显示segmentation fault,有没有大佬能帮忙看一下为什么