struct stack_list* push(struct stack_list* s, const char* c )
{ struct my_stack* p = malloc( 1 * sizeof *p ); struct my_stack* n = NULL; if( NULL == p ) { fprintf(stderr, "malloc() failed\n"); return s; } strcpy(p->arrc, c); p->next = NULL; if( NULL == s ) { fprintf(stderr, "Stack not initialized ?\n"); return s; } else if( NULL == s->head ) { /* printf("Stack is Empty, adding first element\n"); */ s->head = p; return s; } else { /* printf("Stack not Empty, adding in front of first element\n"); */ n = s->head; /* save current head */ s->head = p; /* push new element onto the head */ s->head->next = n; /* attach the earlier saved head to the next of new element * / } return s; }
/* ---------- small helper functions -------------------- */