#include typedef struct stack stack; typedef struct stack { char *tape; int len; char *ptr; } stack; stack *push(stack *s, char c){ if (s == NULL) { stack *outstack = malloc(sizeof(stack)); outstack->tape = malloc(1); outstack->tape[0] = c; outstack->ptr = outstack->tape; outstack->len = 1; return outstack; } s->len++; s->ptr++; s->tape = realloc(s->tape, s->len); *s->ptr = c; return s; } char pop(stack *s){ char c = *s->ptr; *s->ptr = 0; s->len--; s->ptr--; s->tape = realloc(s->tape, s->len); return c; } char peek(stack *s){ return *s->ptr; } void cleanstack(stack *s){ free(s->tape); free(s); }