#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 50

typedef struct {
    char tab[MAX_SIZE];
    int taille;
} pile;

void push_pile(pile* p, char valeur) {
    if (p->taille < MAX_SIZE) {
        p->tab[p->taille++] = valeur;
    } else {
        printf("Erreur: pile pleine\n");
    }
}

char pop_pile(pile* p) {
    if (p->taille > 0) {
        return p->tab[--p->taille];
    }
    printf("Erreur: pile vide\n");
    return '\0';
}

int empty_pile(pile* p) {
    return p->taille == 0;
}

int main(void) {
    pile p = {{0}, 0};
    char ordre[2];

    printf("La pile attend vos ordres \n > ");
    while (scanf("%1s", ordre) == 1) {
        if (ordre[0] == 'q') {
            printf("Au revoir\n");
            break;
        } else if (ordre[0] == '+') {
            scanf(" %c", &ordre[1]);
            push_pile(&p, ordre[1]);
        } else if (ordre[0] == '-') {
            printf("Pop: %c\n", pop_pile(&p));
        } else {
            printf("Commande invalide\n");
        }
        printf("\nLa pile attend vos ordres \n > ");
    }

    return EXIT_SUCCESS;
}
