I have these two structs
struct node{
int val;
struct node *up;
struct node *down;
};
struct stack {
struct node *bottom;
};
The typedef struct is defined in a header file
typedef struct stack stack_set;
I am trying to malloc the structs but I keep getting seg faults when I try to access the node struct. I have tried using malloc on the node struct to no avail.
stack_set *set;
set = malloc(sizeof(stack_set));
set->bottom = NULL;
set = malloc(sizeof(struct node));
set->bottom->val = NULL;
return set;
I hit a seg fault on the second last line of code.
How do I properly malloc my code so I don't keep throwing seg faults?
I haven't been able to find an example that could aid in resolving mine.
Thanks