MODIF correction erreur v1

master
Matheo THIERRY 2 years ago
parent 82690d94a0
commit 227c5450ec

@ -89,29 +89,31 @@ int chargeretudiant(char nomFich[], listetuinfo *tetu[], int tmax){
//enregistrement ========================================================================================
void enregistrementcarte(FILE *fe, Maillonchoix* b){
if(b==NULL){return;}
fprintf(fe, "%s\n%s\n%d\n%d\n", b->Ville, b->dep, b->decision, b->validation);
enregistrementcarte(fe, b.suivant, nb-1);
free(b);
void enregistrementcarte(FILE *fe, Maillonchoix* carte, int nb){
if(carte==NULL){return;}
fprintf(fe, "%s\n%s\n%d\n%d\n", carte->Ville, carte->dep, carte->decision, carte->validation);
enregistrementcarte(fe, carte->suivant, nb-1);
free(carte);
}
void enregistrementinfo(FILE *fe, listetuinfo etu){
Listchoixdept b;
int i=0;
b = etu.carte;
fprintf(fe, "%d\n%s\n%s\n%d %d %d %d\n%d\n", etu->numeroetu, etu->nometu, etu->prenometu, etu->notes, etu->nbchoix);
fprintf(fe, "%d\n%s\n%s\n%d %d %d %d\n%d\n", etu.numeroetu, etu.nometu, etu.prenometu, etu.notes, etu.nbchoix);
enregistrementcarte(fe, b, etu.nbchoix);
}
int enregistrementetudiant(char nomFich[], listetuinfo *tetu[], int nb){
int i=0;
FILE *fe;
listetuinfo etu;
fe = fopen( nomFich, "w");
if(fe==NULL){printf("<! pb fichier in enregistrementetudiant !>\n");return-1;}
fprintf(fe, "%d\n", nb);
for(i=0; i<nb; i++){
enregistrementinfo(fe, tetu[i]);
etu = tetu[i];
enregistrementinfo(fe, etu);
free(tetu[i]);
}
fclose(fe);
@ -123,23 +125,23 @@ int enregistrementetudiant(char nomFich[], listetuinfo *tetu[], int nb){
//général fonction for ajouter modifier et supprimer ===========
void affichagedep(MaillonDept* b){
if(b==NULL){return;}
printf("%s", b->departement);
affichagedep(b.suivant);
void affichagedep(MaillonDept* carte){
if(carte==NULL){return;}
printf("%s", carte->departement);
affichagedep(carte->suivant);
}
void affichagecarte(Maillonchoix* carte){
if(carte==NULL){return;}
printf("%s - %s\n", carte->Ville, carte->dep);
afficherchoix(carte.suivant);
afficherchoix(carte->suivant);
}
void affichageville(Maillon *tville[], int nbville){
int i;
Listdept b;
for(i=0; i<nbville; i++){
b = tville[i].ldept;
b = tville[i]->ldept;
printf("%s :\n", tville[i]->Ville);
affichagedep(b);
printf("\n");
@ -148,20 +150,21 @@ void affichageville(Maillon *tville[], int nbville){
void affichervillechoix(Maillon villechoix){
int i;
Listdept b;
b = villechoix.ldept;
printf("%s :\n", villechoix->Ville);
affichagedep(b);
Listdept ldep;
ldep = villechoix.ldept;
printf("%s :\n", villechoix.Ville);
affichagedep(ldep);
printf("\n");
}
int cherchelistcorrespond(MaillonDept* dep, char choixdep[]){
if(dep==NULL){return -1}
if(dep==NULL){return -1;}
if(strcmp(dep->departement,choixdep)==0){return 1;}
return cherchelistcorrespond(dep.suivant);
return cherchelistcorrespond(dep->suivant, choixdep);
}
int correspondville(char choixville[], char choixdep[], Maillon *tville[], int nbville){
int i, ok;
Listdept b;
for(i=0; i<nbville; i++){
if(strcmp(tville[i]->Ville,choixville)==0){
@ -180,7 +183,7 @@ int correspondcarte(char choixville[], char choixdep[], Maillonchoix* carte){
return 1;
}
}
correspondcarte(choixville, choixdep, carte.suivant);
correspondcarte(choixville, choixdep, carte->suivant);
}
//ajouter ===============================================================================================
@ -193,7 +196,7 @@ void choix(Maillon *tville[], int nbville, char choixville[], char choixdep[]){
printf("departement : \n");
fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0';
ok = correspondville(choixville, choixdep, tville[i], nbville);
ok = correspondville(choixville, choixdep, tville, nbville);
while(ok!=1){
printf("ville : \n");
fgets(choixville, 31, stdin);
@ -201,28 +204,28 @@ void choix(Maillon *tville[], int nbville, char choixville[], char choixdep[]){
printf("departement : \n");
fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0';
ok = correspondville(choixville, choixdep, tville[i], nbville);
ok = correspondville(choixville, choixdep, tville, nbville);
}
}
Listchoixdept ajoutercarte(Maillonchoix* a, char choixville, char choixdep){
Listchoixdept ajoutercarte(Maillonchoix* a, char choixville[], char choixdep[]){
Maillonchoix* carte;
carte = (Maillonchoix*)malloc(sizeof(Maillonchoix));
if(carte==NULL){printf("<! erreur malloc in ajoutercarte !>\n");exit(1);}
strcpy(carte->Ville,choixville);
strcpy(carte->departement,choixdep);
strcpy(carte->dep,choixdep);
carte->decision=0;
carte->validation=0;
carte->suviant=a;
carte->suivant=a;
return carte;
}
int allajoutprocess(Maillon *tville[], listetuinfo etu, int nbville){
int i;
int i, ok;
Listchoixdept b;
b = etu.carte;
char choixville[31], choixdep[31];
afficheville(tville, nbville);
affichageville(tville, nbville);
choix(tville, nbville, choixville, choixdep);
ok = correspondcarte(choixville, choixdep, b);
if(ok==0){b = ajoutercarte(b, choixville, choixdep);}
@ -232,6 +235,7 @@ int allajoutprocess(Maillon *tville[], listetuinfo etu, int nbville){
//modifier ==============================================================================================
void choix2(Listchoixdept lcarte, char choixville[], char choixdep[]){
int ok;
printf("ville : \n");
fgets(choixville, 31, stdin);
choixville[strlen(choixville)-1]='\0';
@ -250,7 +254,7 @@ void choix2(Listchoixdept lcarte, char choixville[], char choixdep[]){
}
}
void choixdep(char choixville[], char choixdep[], Maillon *tville[], int nbville){
void fchoixdep(char choixville[], char choixdep[], Maillon *tville[], int nbville){
int ok;
printf("\n< quel departement voulez vous choisir ? >\n==>");
fgets(choixdep, 31, stdin);
@ -264,22 +268,22 @@ void choixdep(char choixville[], char choixdep[], Maillon *tville[], int nbville
}
}
listetuinfo choixmodifcarte(char choixville[], char choixdep[], Maillon *tville[], int nbville){
if(b==NULL){return -1;}
Listdept dep;
if(strcmp(b->Ville,choixville)==0){
if(strcmp(b->dep,choixdep)==0){
choixdep(choixville, choixdep, tville, nbville);
b->dep=choixville;
return b;
Maillonchoix choixmodifcarte(Maillonchoix dep, char choixville[], char choixdep[]){
Maillonchoix dep;
if(dep==NULL){exit(1);}
if(strcmp(dep->Ville,choixville)==0){
if(strcmp(dep->dep,choixdep)==0){
fchoixdep(choixville, choixdep, tville, nbville);
dep->dep=choixville;
return dep;
}
}
b->suivant = choixmodifcarte(b.suivant, choixville, choixdep);
dep->suivant = choixmodifcarte(dep.suivant, choixville, choixdep);
}
int correspondvilleonly(char choixville[], Maillon ville){
Listdept b;
if(strcmp(ville->Ville,choixville)==0){
if(strcmp(ville.Ville,choixville)==0){
affichervillechoix(ville);
return 1;
}
@ -295,8 +299,9 @@ void modificationcarte(listetuinfo etu, Maillon *tville[], int nbville){
for(i=0; i<nbville; i++){
ok = correspondvilleonly(choixville, tville[i]);
if(ok==1){
choixdep(choixville, choixdep, tville, nbville);
fchoixdep(choixville, choixdep, tville, nbville);
lcarte = choixmodifcarte(choixville, choixdep, tville, nbville);
etu.carte=lcarte;
}
else{printf("\t< choix deja existant >\n");}
}
@ -304,9 +309,9 @@ void modificationcarte(listetuinfo etu, Maillon *tville[], int nbville){
//supprimer =============================================================================================
Maillonchoix suppressioncartechoix(char choixville[], char choixdep[], Maillonchoix carte){
Maillon tmp;
if(carte==NULL){return;}
Maillonchoix suppressioncartechoix(char choixville[], char choixdep[], Maillonchoix* carte){
Maillonchoix* premier, tmp;
if(carte==NULL){exit(1);}
if(strcmp(carte->Ville,choixville)==0){
if(strcmp(choixdep,carte->dep)==0){
tmp=carte->suivant;
@ -314,10 +319,10 @@ Maillonchoix suppressioncartechoix(char choixville[], char choixdep[], Maillonch
return tmp;
}
}
suppressioncartechoix(choixville, choixdep, carte.suivant);
carte = suppressioncartechoix(choixville, choixdep, carte.suivant);
}
void suppcarte(listetuinfo etu,){
void suppcarte(listetuinfo etu){
int i, ok;
char choixville[31], choixdep[31];
Listchoixdept lcarte;

Loading…
Cancel
Save