boot.dev lesson answers for the course: Learn Memory Management in C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

18 lines
358 B

#include <stdlib.h>
#include "snekstack.h"
my_stack_t *stack_new(size_t capacity)
{
my_stack_t *stack = (my_stack_t *)malloc(sizeof(my_stack_t));
if (stack == NULL) return NULL;
stack->count = 0;
stack->capacity = capacity;
stack->data = malloc(sizeof(void*) * capacity);
if (stack->data == NULL) {
free(stack);
return NULL;
}
return stack;
}