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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| code:
#include <stdio.h>
#include <stdlib.h>
struct listpetit
{
char x;
listpetit *next;
};
struct list
{
int num;
listpetit *debut;
list *next;
};
list* remplir()
{
char a,b;
list *p,*tete;
listpetit *q, *tetep;
//alouer liste des entiers
tete=(list *)malloc(sizeof(list));
p=tete;
do {
printf ("Donner un entier ");
scanf("%d",&p->num);
//alouer liste des caractere
p->debut=(listpetit *)malloc(sizeof(listpetit));
tetep=p->debut;
q=p->debut;
do
{
printf ("Donner un caractere ");
scanf(" %c",&q->x);
printf("Voulez vous saisir un autre char taper y ou n \n");
scanf(" %c",&b);
if (b == 'n')
q->next=NULL;
else if (b=='y')
{
q->next=(listpetit *)malloc(sizeof(listpetit));
q=q->next;
}
}while(b != 'n');
printf("Voulez vous saisir un autre entier taper y ou n \n");
scanf(" %c",&a);
if (a == 'n')
p->next=NULL;
else if (a=='y')
{
p->next=(list *)malloc(sizeof(list));
p=p->next;
}
}while(a != 'n');
return (tete);
}
void main()
{
char a;
list *Q; listpetit *h;
Q=remplir();
printf("\naffichage \n");
while(Q !=NULL)
{
printf("\n %d \n",Q->num);
if(Q->debut != NULL)
{
printf(" %c\n",Q->debut->x);
Q->debut=Q->debut->next;
}
Q= Q->next;
}
} |
Partager