Edit: nevermind that code...
This should give you an idea of what I'm talking about;
the structures(not global):
Code:
struct stack_node_t{
struct stack_node_t *next;
void *data;
};
struct stack_t{
struct stack_node_t **stack_ptr;
struct stack_node_t *root;
int size;
int max;
};
Code:
void push(struct stack_t *stack, void *data){
if(stack->size < stack->max){
if(!stack->size){
stack->root = malloc(sizeof(struct stack_node_t));
stack->root->next = NULL;
stack->root->data = data;
}
else{
(*stack->stack_ptr)->next = malloc(sizeof(struct stack_node_t));
stack->stack_ptr = &(*stack->stack_ptr)->next;
(*stack->stack_ptr)->next = NULL;
(*stack->stack_ptr)->data = data;
}
stack->size++;
}
else{
fputs("ERROR: Stack overflow\n", stdout);
}
}