Bonjour.
Voici les codes de mon programme d'ajout d'information en tête dans ma liste chaînée :
Alors, j'essaie tant bien que mal d'afficher mes obtentions, mais ca plante a chaque fois. Si quelqu'un voit une solution, ce serait super !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #define a 100 #define sp printf("\n") typedef struct fic { char nom[a]; int x; struct fic *svt; struct fic *pcd; }fic; fic ajouterentete(fic*); void main(void) { fic *ptrfic=NULL,*tmp=NULL; *ptrfic=ajouterentete(ptrfic); if(ptrfic==NULL) puts("liste vide"); else{ puts(ptrfic->nom); printf("%d",ptrfic->x); } sp; system("pause"); } fic ajouterentete(fic *ptrfic) { fic *newptr=malloc(sizeof(fic)); char nom[a]; int x; puts("Notez votre nom:"); gets(nom); puts("age:"); scanf("%d",&x); newptr->x=x; *newptr->nom=(char)malloc((strlen(nom)+1)*sizeof(char)); strcpy(newptr->nom,nom); newptr->svt=ptrfic; return *newptr; }![]()
Partager