【发布时间】:2014-08-19 15:27:37
【问题描述】:
我有这两个结构
struct node{
int val;
struct node *up;
struct node *down;
};
struct stack {
struct node *bottom;
};
typedef 结构体在头文件中定义
typedef struct stack stack_set;
我正在尝试malloc 结构,但是当我尝试访问node 结构时,我不断收到段错误。我尝试在 node 结构上使用 malloc 无济于事。
stack_set *set;
set = malloc(sizeof(stack_set));
set->bottom = NULL;
set = malloc(sizeof(struct node));
set->bottom->val = NULL;
return set;
我在代码的倒数第二行遇到了段错误。
我如何正确地 malloc 我的代码,这样我就不会一直抛出 seg 错误?
我找不到可以帮助解决我的问题的示例。
谢谢
【问题讨论】:
标签: c struct segmentation-fault malloc