1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "filo.h"
typedef struct {
char pseudo[32];
int annee_inscription;
} membre;
#define NB_INT 5
#define NB_MEMBRE 2
int main(int argc,char *argv[])
{
int *tab_int;
int *ptr_int;
filo *filo_int = filo_new(sizeof(int));
membre *tab_membre;
membre *ptr_membre;
filo *filo_membre = filo_new(sizeof(membre));
int i,count;
tab_int = malloc(NB_INT*sizeof(int)); /* j'alloue mon tableau d'entiers */
for (i=0;i<NB_INT;i++) tab_int[i] = i; /* je le remplis avec 0, 1, ... 4) */
tab_membre = malloc(NB_MEMBRE*sizeof(membre)); /* analogue avec mon tableau de membres */
strcpy(tab_membre[0].pseudo,"gentil-personnage");
tab_membre[0].annee_inscription = 2009;
strcpy(tab_membre[1].pseudo,"plxpy");
tab_membre[1].annee_inscription = 2009;
/* je remplis mes deux piles */
for (i=0;i<NB_INT;i++) filo_push(filo_int,tab_int+i);
for (i=0;i<NB_MEMBRE;i++) filo_push(filo_membre,tab_membre+i);
/* je reinitialise mes tableaux (pour montrer que ce sont les piles qui ont copie mes donnees) */
memset(tab_int,0,NB_INT*sizeof(int));
memset(tab_membre,0,NB_MEMBRE*sizeof(membre));
fprintf(stdout,"depilage table d'entiers\n");
count = 1;
while (ptr_int = filo_pull(filo_int)) {
fprintf(stdout,"position %d : %d\n",count,*ptr_int);
free(ptr_int);
count++;
}
fprintf(stdout,"depilage table membres\n");
count = 1;
while (ptr_membre = filo_pull(filo_membre)) {
fprintf(stdout,"position %d : %s (%d)\n",count,ptr_membre->pseudo,ptr_membre->annee_inscription);
free(ptr_membre);
count++;
}
} |
Partager