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 60 61 62 63 64 65 66 67 68
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct t_liste
{char *nom; char *prenom; char *courriel; struct t_liste *prec;}Maillon;
Maillon *pMaillon=NULL;
Maillon *pFirst=NULL;
Maillon *pTempo=NULL;
int main ()
{
int i=1;
int n=0;
int s;
char Nom[32],Prenom[32],Courriel[32];
FILE *pFichier=NULL;
pFichier=fopen("groupes.txt","r");
do
{
s=fscanf(pFichier,"%s%s%s",Nom,Prenom,Courriel);
{
printf("%d) %s %s %s\n",i++,Nom,Prenom,Courriel);}
pTempo=(Maillon *)malloc(sizeof(Maillon));
if(pTempo==NULL) exit(1);
pTempo->nom=Nom;
pTempo->prenom=Prenom;
pTempo->courriel=Courriel;
pTempo->prec=pMaillon;
pMaillon=pTempo;
}
while (s!=EOF);
/*boucle d'affichage de la pile*/
while(pMaillon)
{
n++;
printf("pile : %s %s %s \n",pMaillon->nom,pMaillon->prenom,pMaillon->courriel);
pMaillon=pMaillon->prec;
}
printf("longueur de la pile n=%d\n",n);
free(pTempo);
fclose(pFichier);
return 0;
} |
Partager