63 lines
1.2 KiB
C
63 lines
1.2 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include "file.h"
|
||
|
|
||
|
#define TAILLE_MIN 30
|
||
|
#define TAILLE_INC 10
|
||
|
|
||
|
char *saisie(const char* invite) {
|
||
|
char *temp = (char *) malloc(TAILLE_MIN);
|
||
|
int c, i=0, taille = TAILLE_MIN;
|
||
|
|
||
|
printf("\n%s", invite);
|
||
|
while(((c=getchar())!=EOF)&&(c!='\n')) {
|
||
|
if (i>=taille) {
|
||
|
taille += TAILLE_INC;
|
||
|
temp = (char *) realloc(temp, taille);
|
||
|
}
|
||
|
temp[i++] = c;
|
||
|
}
|
||
|
temp = (char *) realloc(temp, i+1);
|
||
|
temp[i] = '\0';
|
||
|
return temp;
|
||
|
}
|
||
|
|
||
|
int main(void) {
|
||
|
int choix = 0;
|
||
|
char *s;
|
||
|
file f = {NULL, NULL};
|
||
|
|
||
|
while (choix != '3') {
|
||
|
printf("\nFaites votre choix :\n");
|
||
|
printf("\t1. nouveau client\n");
|
||
|
printf("\t2. client suivant\n");
|
||
|
printf("\t3. fermer boutique\n");
|
||
|
printf("? ");
|
||
|
choix = getchar();
|
||
|
while(getchar() != '\n');
|
||
|
switch (choix) {
|
||
|
case '1':
|
||
|
s = saisie("Nom du client : ");
|
||
|
file_push(f, s);
|
||
|
break;
|
||
|
case '2':
|
||
|
if (file_empty(f)) {
|
||
|
printf("\nAucun Client a l'horizon...\n");
|
||
|
} else {
|
||
|
s = file_pop(f);
|
||
|
printf("\nClient suivant : %s\n", s);
|
||
|
free(s);
|
||
|
}
|
||
|
break;
|
||
|
case '3':
|
||
|
printf("\nOn ferme !\n\n");
|
||
|
break;
|
||
|
default:
|
||
|
printf("Ne tapez pas n'importe quoi !\n");
|
||
|
}
|
||
|
}
|
||
|
file_clear(f);
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|