-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathmain.c
executable file
·108 lines (98 loc) · 2.5 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include "enzyme.h"
#include "pathway.h"
#include "liste.h"
#define MAX 3
void afficheMenu();
void saisie(liste);
void affichage(liste);
void ouvrir(liste, char *);
void sauvegarder(liste);
static int cpt=0;
int main(int argc, char *argv[]) {
liste list_pathway = creerliste();
int reponse;
char *nom_fichier;
nom_fichier=(char *)malloc(sizeof(char)*30);
while(1) {
afficheMenu();
scanf("%d", &reponse);
switch (reponse) {
case 1: {saisie(list_pathway);break;}
case 2: {affichage(list_pathway);break; }
case 3: {sauvegarder(list_pathway);break;}
case 4: {
printf("Quel fichier voulez-vous ouvrir?\n");
scanf("%s",nom_fichier);
ouvrir(list_pathway, nom_fichier);
break;
}
case 5: {list_pathway=supprimer(list_pathway);break;}
case 0: {return 0;}
}
}
return 0;
}
void saisie(liste list_pathway) {
int i;
char *nom;
int poids;
int nombre;
printf("Combien de voies?\n");
scanf("%d", &nombre);
for (i=0; i<nombre; i++) {
ptr_pathway item=creerpathway();
saisie_voie(item);
ajouter(list_pathway,item);
cpt++;
}
}
void affichage(liste list_pathway) {
int i;
if (case_vide(list_pathway)) printf("Le tableau est vide, veuillez le remplir.\n");
else {
afficherliste(list_pathway);
}
}
void ouvrir(liste list_pathway, char *nom) {
FILE *fichier;
ptr_pathway item;
char *_nom;
int poids;
fichier = fopen(nom, "r");
if (fichier == NULL)
printf("Mauvais fichier\n");
else {
do {
item = creerpathway();
ouvrir_voie(item, fichier);
ajouter(list_pathway,item);
}
while (fgetc(fichier) != EOF);
fclose(fichier);
}
printf("Chargement terminé\n");
}
void sauvegarder(liste list_pathway) {
liste tmp = list_pathway;
FILE *out;
int i;
out=fopen("resul","w");
if (case_vide(list_pathway)) printf("Le tableau est vide, veuillez le remplir.\n");
else {
while (!case_vide(tmp)) {
sauvegarder_voie(retourcontenu(tmp), out);
tmp=case_suivante(tmp);
}
}
fclose(out);
}
void afficheMenu() {
printf("Programme Enzyme\n");
printf("1. Entrer informations\n");
printf("2. Afficher\n");
printf("3. Sauvegarder\n");
printf("4. Ouvrir un fichier\n");
printf("5. Supprimer\n");
}