Voilà, je suis sensée remplir une liste chaînée mais le problème c'est que mes pointeurs ne passe pas bien dans mes fonctions, résultat:je n'ai pas la bonne valeur de mon ptrDeb à l'arrivée ce qui fait qu'il est toujours égal à NULL
voici la fonction ou est déclaré ptrDeb:
Je fais donc passer mon pointeur à la fonction ResCrea
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
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 void MenuRes(FILE *FiFestiv, FILE *FiFestivInd) { //int erreur; int choix,indice,i,nbC,icf; ListeR *ptrDeb=NULL; concert lectC; festival lectF; TabTemp TabTemp[LIMTAB]; index tabindex[LIMTAB]; FiFestiv = fopen("FiFestiv.Dat","rb"); FiFestivInd = fopen("FiFestiv.Ind","rb"); indice=ChargeTabInd(FiFestivInd,tabindex); fclose(FiFestivInd); indice--; for(i=0;i<3 && i<=indice;i++) { lectC=LectureCP(FiFestiv,tabindex[i].depDebFic); TabTemp[i].adrFich=tabindex[i].depDebFic; TabTemp[i].nbPlRes=lectC.nbIns; TabTemp[i].nbPlA=0; TabTemp[i].nbPlE=0; strcpy(TabTemp[i].ind,"c"); strcpy(TabTemp[i].codeT,lectC.code); TabTemp[i].nbPlMax=lectC.nbMax; } while(i<=indice) { lectF=LectureF(FiFestiv,tabindex[i].depDebFic); nbC=lectF.nbConcerts; strcpy(TabTemp[i].ind,"f"); i++; for(icf=0;icf<nbC;icf++,i++) { lectC=LectureCP(FiFestiv,tabindex[i].depDebFic); TabTemp[i].adrFich=tabindex[i].depDebFic; TabTemp[i].nbPlRes=lectC.nbIns; TabTemp[i].nbPlA=0; TabTemp[i].nbPlE=0; strcpy(TabTemp[i].ind,"c"); strcpy(TabTemp[i].codeT,lectC.code); TabTemp[i].nbPlMax=lectC.nbMax; } } choix=0; while(choix!=4) { flushall(); clrscr(); printf("\n\n\n\n\t\t\t********************************\n"); printf("\t\t\t* *\n"); printf("\t\t\t* 1. Creation *\n"); printf("\t\t\t* *\n"); printf("\t\t\t* 2. Impression *\n"); printf("\t\t\t* *\n"); printf("\t\t\t* 3. Annulation *\n"); printf("\t\t\t* *\n"); printf("\t\t\t* 4. Menu principal *\n"); printf("\t\t\t* *\n"); printf("\t\t\t********************************\n"); printf("\n\n\t\t\t\tChoix: "); choix = getchar();clrscr();flushall(); switch (choix) { case '1' : ResCrea(FiFestiv,FiFestivInd,TabTemp,tabindex,ptrDeb,i); fflush(stdin); break; case '2' : Impression(FiFestiv,FiFestivInd,ptrDeb); break; case '3' : break; case '4' : MenuPrinc(); default: clrscr(); printf("\n\n\n\n\n\n\t\t\t\t!!!!!!Choix invalide!!!!!!"); getch(); clrscr(); } } }
Ensuite je le fais passer à AjoutListe
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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 int ResCrea(FILE *FiFestiv, FILE *FiFestivInd,TabTemp TabTemp[],index tabIndex[],ListeR *ptrDeb,int i) { char NomPre[LIMCHAR],codeE[4]; int ind,choix,ir,it,nbA,nbE,nbC=0,newR,ok,ic,tel; festival lectF; //TabTempP TabPers[LIMTAB]; //TabTempR TabRes[LIMTAB]; FiFestiv = fopen("FiFestiv.dat", "rb"); FiFestivInd = fopen("FiFestiv.ind", "rb"); if (i==0) { printf ("!!!Liste concerts vide!!!"); getch(); } else { printf("\n\nveuillez introduire votre Nom(XXX=fin):"); scanf("%s",&NomPre); printf("\n\nveuillez introduire votre telephone: "); scanf("%d",&tel); while(strcmp(NomPre,"XXX")!=0) { printf("desirez vous un abonnement(oui=1/non=0):"); scanf("%d",&ind); choix= menuchoix(); if(choix=='3') { strcpy(codeE,"XXX"); } else { printf("veuillez introduire le code (XXX=fin):"); scanf("%s",&codeE); } while(strcmp(codeE,"XXX")!=0) { for(ir=0;ir<=i && strcmp(codeE,tabIndex[ir].code)!=0;ir++); if(ir>i) { printf("\n\n\t\t!!! Code n'existe pas !!!\n\n"); getch(); choix=menuchoix(); if(choix=='3') { strcpy(codeE,"XXX"); } else { printf("veuillez introduire le code (XXX=fin):"); scanf("%s",&codeE); } } else { printf("combien d'adultes: "); scanf("%d",&nbA); printf("combien d'enfants: "); scanf("%d",&nbE); if(choix=='1') { for(it=0;it<=i && strcmp(codeE,TabTemp[it].codeT)!=0;it++); TabTemp[it].nbPlRes+=nbA+nbE; if(TabTemp[it].nbPlRes>TabTemp[it].nbPlMax) { TabTemp[it].nbPlRes-=nbA+nbE; printf("plus de place concert"); getch(); } else { TabTemp[it].nbPlA+=nbA; TabTemp[it].nbPlE+=nbE; AjoutListe(NomPre,ind,ptrDeb,TabTemp,tel,it); } } else { if(choix=='2') { for(it=0;it<=i && strcmp(codeE,tabIndex[it].code)!=0;it++); lectF= LectureF(FiFestiv,tabIndex[it].depDebFic); nbC=lectF.nbConcerts; ok=0; ic=0; it++; while(ic<nbC && ok==0) { TabTemp[it].nbPlRes+=nbA+nbE; if(TabTemp[it].nbPlRes>TabTemp[it].nbPlMax) { TabTemp[it].nbPlRes-=nbA+nbE; printf("Plus de place pour ce festival"); getch(); ok=1; } else { TabTemp[it].nbPlRes+=nbA+nbE; TabTemp[it].nbPlA+=nbA; TabTemp[it].nbPlE+=nbE; AjoutListe(NomPre,ind,ptrDeb,TabTemp,tel,it); ic++; it++; } } } else { printf("\n\ndesirez-vous faire une nouvelle reservation?(1=oui/0=non):\n"); scanf("%d",&newR); if(newR==1) { printf("\nveuillez introduire votre Nom(XXX=fin):"); scanf("%s",&NomPre); printf("\n\nveuillez introduire votre telephone: "); scanf("%d",&tel); } else { break; //MenuRes(FiFestiv,FiFestivInd); } } } choix= menuchoix(); if(choix=='3') { strcpy(codeE,"XXX"); } else { printf("veuillez introduire le code (XXX=fin):"); scanf("%s",&codeE); } } } printf("\n\ndesirez-vous faire une nouvelle reservation?(1=oui/0=non):\n"); scanf("%d",&newR); if(newR==1) { printf("\nveuillez introduire votre Nom(XXX=fin):"); scanf("%s",&NomPre); printf("\n\nveuillez introduire votre telephone: "); scanf("%d",&tel); } else { MiseAjour(FiFestiv,i,TabTemp); break; //MenuRes(FiFestiv,FiFestivInd); } } } MiseAjour(FiFestiv,i,TabTemp); //MenuRes(FiFestiv,FiFestivInd); return 0; }
Là je fais passer à RechercheRes
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 void AjoutListe(char NomPre[], int ind, ListeR *ptrDeb,TabTemp TabTemp[],int tel,int it) { int erreur,i=0; ListeR *Pprec,*Ptrouv; ListeRtaire *Plist,*plistePrec,*pNewL; Pprec=Ptrouv=NULL; RechercheRes(&ptrDeb,&Pprec,&Ptrouv,NomPre); if(Ptrouv==NULL) { erreur=AjoutRes(NomPre,Pprec,&ptrDeb,ind,TabTemp,tel,it); if(erreur==1) { clrscr(); printf("!!! plus de place memoire !!!"); getch(); } } else { printf("%s",Ptrouv->NomPreCh); Plist=Ptrouv->ptrListe; while(Plist!=NULL && Plist->codeCh!=TabTemp[it].codeT) { i++; plistePrec=Plist; Plist=Plist->PtrSvt; } if(i==9 && ind==0) { printf("!!!cota concert atteint!!!"); getch(); } else { if(Plist==NULL) { pNewL=(ListeRtaire *)malloc(sizeof(ListeRtaire)); if(pNewL==NULL) { printf("\n!!!Plus de place memoire!!!\n"); getch(); } else { strcpy(pNewL->codeCh,TabTemp[it].codeT); printf("\n%s\n",pNewL->codeCh); pNewL->nbAdCh=TabTemp[it].nbPlA; printf("%d\n",pNewL->nbAdCh); pNewL->nbenCh=TabTemp[it].nbPlE; printf("%d\n",pNewL->nbenCh); getch(); pNewL->PtrSvt=NULL; plistePrec->PtrSvt=pNewL; } } else { Plist->nbAdCh+=TabTemp[it].nbPlA; printf("%d\n",Plist->nbAdCh); Plist->nbenCh+=TabTemp[it].nbPlE; printf("%d\n",Plist->nbenCh); getch(); } } } }
et enfin, je fais passer un pointeur de pointeur à AjoutRes vu que j'y modifie ptrDeb
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 void RechercheRes(ListeR *ptrDeb,ListeR **Pprec, ListeR **Ptrouv, char NomPre[]) { *Ptrouv=ptrDeb; while(*Ptrouv!=NULL && strcmp(NomPre,(*Ptrouv)->NomPreCh)!=0) { *Pprec=*Ptrouv; *Ptrouv=(*Ptrouv)->PtrSvt; } }
Voilà donc mon problème c'est qu'après tout ça, pas moyen de récupérer la valeur de ptrDeb dans Rescrea, à chaque fois il se remet à NULL
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
47
48 int AjoutRes(char NomPre[],ListeR *Pprec,ListeR **ptrDeb,int ind,TabTemp TabTemp[],int tel,int it) { ListeR *Pnew; ListeRtaire *Ptaire; Pnew=(ListeR *)malloc(sizeof(ListeR)); if(Pnew==NULL) { return 1; } else { if(Pprec==NULL) { *ptrDeb=Pnew; } else { Pprec->PtrSvt=Pnew; } strcpy(Pnew->NomPreCh,NomPre); printf("%s",Pnew->NomPreCh); Pnew->tel=tel; Pnew->IndCh=ind; Pnew->PtrSvt=NULL; Pnew->ptrListe=NULL; Ptaire=(ListeRtaire *)malloc(sizeof(ListeRtaire)); if(Ptaire==NULL) { printf("\n!!!Plus de place memoire!!!\n"); } else { if(Pnew->ptrListe==NULL) { Pnew->ptrListe=Ptaire; } strcpy(Ptaire->codeCh,TabTemp[it].codeT); printf("\n%s\n",Ptaire->codeCh); Ptaire->nbAdCh=TabTemp[it].nbPlA; printf("%d\n",Ptaire->nbAdCh); Ptaire->nbenCh=TabTemp[it].nbPlE; printf("%d\n",Ptaire->nbenCh); getch(); Ptaire->PtrSvt=NULL; } return 0; } }
Si quelqu'un avait la gentillesse de m'aider un peu ce serait super sympa...merci d'avance
Partager