Bonjour,

j'ai un projet de programmation en c..on nous demande de realiser la version dynamique cad avec les listes chainéees du programme de gestion de documents...j'ai fait un essai cependant il ne fonctionne pas
pourriez vous m'aider a trouver et corriger les erreurs

Voici le code complet:
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
 
#ifndef STRUCTURES_H_INCLUDED 
#define STRUCTURES_H_INCLUDED 
 
 
typedef  struct date_cre 
{ 
    int annee; 
    int mois; 
    int jour; 
}date_cre; 
 
typedef struct document 
{   char nom[20]; 
    int  taille; 
    char type[20]; 
    char cat[20]; 
    date_cre date; 
    struct document *suivant; 
 
}document; 
 
typedef struct Liste 
{ 
    document *premier; 
}Liste; 
 
 
 
#endif // STRUCTURES_H_INCLUDED 
> 
 
 
#ifndef ENTETES_H_INCLUDED 
#define ENTETES_H_INCLUDED 
 
 
Liste *initialisation(); 
void ajout(Liste *liste); 
void suppression(Liste *liste); 
void afficherListe(Liste liste); 
int statistiques(Liste liste); 
 
 
#endif // ENTETES_H_INCLUDED 
 
#include<stdio.h> 
#include<stdlib.h> 
#include<string.h> 
#include "structures.h" 
 
  document *nouveau(char *pnom,int ptaille,char *ptype, char *pcat,int pannee,int pmois,int pjour) 
{ 
    document *c; 
    c=(document *)malloc(sizeof(document)); 
    strcpy(c->nom,pnom); 
    c->taille=ptaille; 
    strcpy(c->type,ptype); 
    strcpy(c->cat,pcat); 
    c->date.annee=pannee; 
    c->date.mois=pmois; 
    c->date.jour=pjour; 
 
    c->suivant=NULL; 
    return c; 
    } 
 
#include"structures.h" 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
 
 
Liste *initialisation() 
{ 
    Liste *liste = malloc(sizeof(*liste)); 
    document *doc = malloc(sizeof(*doc)); 
 
    if (liste == NULL || doc == NULL) 
    { 
        exit(EXIT_FAILURE); 
    } 
    strcpy(doc->nom,'\0'); 
    doc->taille=0; 
    strcpy(doc->type,'\0'); 
    strcpy(doc->cat,'\0'); 
    doc->date.annee=0; 
    doc->date.mois=0; 
    doc->date.jour=0; 
    doc->suivant = NULL; 
    liste->premier = doc; 
 
    return liste; 
} 
 
 
#include<stdio.h> 
#include<stdlib.h> 
#include<string.h> 
#include"structures.h" 
 
 
void ajout(Liste *liste) 
 
{int a; 
  char pnom; 
  int ptaille; 
  char ptype; 
  char pcat; 
  int pannee; 
  int pmois; 
  int pjour; 
 
    /* Création du nouvel élément */ 
  document *p; 
    if (liste == NULL) 
    { 
        exit(EXIT_FAILURE); 
    } 
 
 
    printf("donnez le nom du document\n"); 
    scanf("%s",pnom); 
    printf("donnez la taille du document\n"); 
    scanf("%d",&ptaille); 
    printf("donnez le type du document\n"); 
    scanf("%s",ptype); 
    printf("donnez la catégorie du document\n"); 
    scanf("%s",pcat); 
    printf("donnez la nouvelle annee\n"); 
    scanf("%d",&pannee); 
     printf("donnez le nouvel mois\n"); 
    scanf("%d",&pmois); 
     printf("donnez l nouvel jour\n"); 
    scanf("%d",&pjour); 
 
   p=nouveau(pnom,ptaille,ptype,pcat,pannee,pmois,pjour); 
 
    /* Insertion de l'élément au début de la liste */ 
    p->suivant = liste->premier; 
    liste->premier = p; 
do 
{a=1; 
printf("tapez 0 pour rentrer au menu principal!\n"); 
scanf("%d",&a); 
system("cls"); 
} 
while (a!=0); 
 
return 0; 
} 
 
 
 
#include<stdio.h> 
#include<stdlib.h> 
#include"structures.h" 
#include <string.h> 
 
void suppression(Liste *liste) 
 
{ char supp_nom[20]; 
  int a; 
printf("entrer l\'element de liste que vous voulez supprimer"); 
scanf("%s",supp_nom); 
 
    if (liste == NULL) 
    { 
        exit(EXIT_FAILURE); 
    } 
    do 
    { 
    if (strcmp(liste->premier->nom,supp_nom)!=0) 
           liste->premier=liste->premier->suivant; 
    else 
    { 
        document *aSupprimer = liste->premier; 
        liste->premier = liste->premier->suivant; 
        free(aSupprimer); 
    } 
 
}while (strcmp(liste->premier->nom,supp_nom)!=0); 
 
a=1; 
do 
{printf("tapez 0 pour rentrer au menu principal!\n"); 
scanf("%d",&a); 
system("cls"); 
} 
while (a!=0); 
} 
 
#include<stdio.h> 
#include<stdlib.h> 
#include"structures.h" 
 
 
void afficherListe(Liste liste) 
{int a; 
document *actuel = liste.premier; 
 
    while (actuel != NULL) 
    { 
        printf("\n nom %s : ", actuel->nom); 
        printf("\n taille %d : ", actuel->taille); 
        printf("\n type %s : ", actuel->type); 
        printf("\n categorie %s ", actuel->cat); 
        printf("date:  "); 
          printf("\n annee%d : ", actuel->date.annee); 
          printf("\n mois%d : ", actuel->date.mois); 
          printf("\n jour%d : ", actuel->date.jour); 
        actuel = actuel->suivant; 
    } 
    printf("NULL\n"); 
 
do 
{a=1; 
printf("tapez 0 pour rentrer au menu principal!\n"); 
scanf("%d",&a); 
system("cls"); 
} 
while (a!=0); 
} 
 
#include<stdio.h> 
#include<stdlib.h> 
#include"structures.h" 
#include"entetes.h" 
 
void menu(Liste *liste) 
{ 
int choix; 
 
     {  printf("============================================================"); 
        printf("            ***Bienvenue!***"); 
        printf("============================================================"); 
        printf("Effectuez votre choix:\n"); 
        printf("    1- Ajouter un document\n"); 
        printf("    2- chercher un document\n"); 
        printf("    3- Supprimer un document\n"); 
        printf("    4- Modifier un document\n"); 
        printf("    5- Trier les documents\n"); 
        printf("    6- Statistiques\n"); 
        printf("    7- Liste des documents\n"); 
        printf("    0- Quitter\n\n\n"); 
        scanf("%d",&choix); 
        switch(choix) 
        {case 0:choix=0; break; 
        case 1: {choix=0; system("cls"); ajout(liste);  menu(liste); break;}; 
        //case 2: choix=0; system("cls"); rechercher(doc);     menu(doc); break; 
        case 3: {choix=0; system("cls"); suppression(liste);   menu(liste); break;}; 
        //case 4: choix=0; system("cls"); modifier(doc);     menu(doc); break; 
        //case 5: choix=0; system("cls"); trier(doc);      menu(doc); break; 
        //case 6: choix=0; system("cls"); statistiques(doc); menu(doc); break; 
        case 7: {choix=0; system("cls"); afficherListe(*liste); menu(liste); break;}; 
        default:system("cls"); 
                printf("       Choix invalide!\n\n\n");break;} 
         }while(choix!=0); 
   return; 
} 
 
 
#include<stdio.h> 
#include<stdlib.h> 
#include"structures.h" 
 
 
void modification(Liste *liste) 
{int a; 
char *nvnom[20]; 
int nvtaille; 
char *nvtype[20]; 
char *nvcat[20]; 
int nvannee; 
int nvmois; 
int nvjour; 
char nom_modif[20]; 
document *p; 
 
  printf("Consultez la liste avant d\'effectuer une modification:\n"); 
  afficherListe(liste); 
  printf("\n \n"); 
  printf ("donner le nom du document que vous voulez modifier :\n"); 
  scanf("%s=",nom_modif); 
 
    if (liste == NULL) 
    { 
        exit(EXIT_FAILURE); 
    } 
 
    if (liste->premier->nom != nvnom) 
    liste->premier=liste->premier->suivant; 
    else 
    { 
    printf("donnez le nom du document\n"); 
    scanf("%s",nvnom); 
    printf("donnez la taille du document\n"); 
    scanf("%d",&nvtaille); 
    printf("donnez le type du document\n"); 
    scanf("%s",nvtype); 
    printf("donnez la catégorie du document\n"); 
    scanf("%s",nvcat); 
    printf("donnez la nouvelle annee\n"); 
    scanf("%d",&nvannee); 
     printf("donnez le nouvel mois\n"); 
    scanf("%d",&nvmois); 
     printf("donnez l nouvel jour\n"); 
    scanf("%d",&nvjour); 
 
    p=nouveau(nvnom,nvtaille,nvtype,nvcat,nvannee,nvmois,nvjour); 
    liste->premier=p; 
    } 
do 
{a=1; 
printf("tapez 0 pour rentrer au menu principal!\n"); 
scanf("%d",&a); 
system("cls"); 
} 
while (a!=0); 
} 
 
#include<stdio.h> 
#include<stdlib.h> 
#include"structures.h" 
 
 
int main() 
{ 
    Liste *list = initialisation(); 
    menu(list); 
    return 0; 
}

REMARQUE:les profs nous demandeneet de creer chaque fonction toute seule dans un fichier source,les entetes et les structures dans les fichiers headers...

Merci d'avance.