diff --git a/lib/stack.c b/lib/stack.c index 60a25ca..53d800d 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -6,7 +6,7 @@ struct stack *initialize_stack() { struct stack *stack = NULL; - stack = malloc(sizeof(stack)); + stack = malloc(sizeof(*stack)); stack->card = NULL; stack->next = NULL; @@ -46,13 +46,13 @@ void push(struct stack **stack, struct card *card) { } } -struct stack *pop(struct stack *stack) { +struct stack *pop(struct stack **stack) { struct stack *popped_entry = NULL; - if(!empty(stack)) { - popped_entry = stack; - popped_entry = NULL; - stack = stack->next; + if(!empty(*stack)) { + popped_entry = *stack; + *stack = (*stack)->next; + popped_entry->next = NULL; } return(popped_entry); diff --git a/lib/stack.h b/lib/stack.h index e1b8f21..6b277e8 100644 --- a/lib/stack.h +++ b/lib/stack.h @@ -10,6 +10,6 @@ struct stack *initialize_stack(); bool empty(struct stack *); int length(struct stack *); void push(struct stack **, struct card *); -struct stack *pop(struct stack *); +struct stack *pop(struct stack **); #endif