MODIF add modifier et supp

master
Matheo THIERRY 2 years ago
parent 501b87cf95
commit 82690d94a0

@ -38,8 +38,8 @@ combien de fonctionnalité en combien de fonction ...
V charger fichier V charger fichier
V ajouter choix V ajouter choix
- modifier choix V modifier choix
- supp choix V supp choix
V enregistrer fichier V enregistrer fichier
- section affichage - section affichage
@ -117,8 +117,11 @@ int enregistrementetudiant(char nomFich[], listetuinfo *tetu[], int nb){
fclose(fe); fclose(fe);
} }
//ajouter =============================================================================================== //affichage =============================================================================================
// sous-partie -> affichage tville avec uniquement les dep ===========
//général fonction for ajouter modifier et supprimer ===========
void affichagedep(MaillonDept* b){ void affichagedep(MaillonDept* b){
if(b==NULL){return;} if(b==NULL){return;}
@ -126,6 +129,12 @@ void affichagedep(MaillonDept* b){
affichagedep(b.suivant); affichagedep(b.suivant);
} }
void affichagecarte(Maillonchoix* carte){
if(carte==NULL){return;}
printf("%s - %s\n", carte->Ville, carte->dep);
afficherchoix(carte.suivant);
}
void affichageville(Maillon *tville[], int nbville){ void affichageville(Maillon *tville[], int nbville){
int i; int i;
Listdept b; Listdept b;
@ -137,16 +146,22 @@ void affichageville(Maillon *tville[], int nbville){
} }
} }
//========================== -fin de sous-partie void affichervillechoix(Maillon villechoix){
int i;
Listdept b;
b = villechoix.ldept;
printf("%s :\n", villechoix->Ville);
affichagedep(b);
printf("\n");
}
int cherchelistcorrespond(MaillonDept* b, char choixdep[]){ int cherchelistcorrespond(MaillonDept* dep, char choixdep[]){
if(b==NULL){return -1} if(dep==NULL){return -1}
if(strcmp(b->departement,choixdep)==0){return 1;} if(strcmp(dep->departement,choixdep)==0){return 1;}
return cherchelistcorrespond(b.suivant); return cherchelistcorrespond(dep.suivant);
} }
int correspond(Maillon *tville[], int nbville, char choixville[], char choixdep[]){ int correspondville(char choixville[], char choixdep[], Maillon *tville[], int nbville){
int i;
Listdept b; Listdept b;
for(i=0; i<nbville; i++){ for(i=0; i<nbville; i++){
if(strcmp(tville[i]->Ville,choixville)==0){ if(strcmp(tville[i]->Ville,choixville)==0){
@ -158,31 +173,35 @@ int correspond(Maillon *tville[], int nbville, char choixville[], char choixdep[
return -1; return -1;
} }
void affichechoix(Maillon *tville[], int nbville, char choixville[], char choixdep[]){ int correspondcarte(char choixville[], char choixdep[], Maillonchoix* carte){
affichageville(tville); if(carte==NULL){return 0;}
printf("ville : "); if(strcmp(choixville,carte->Ville)==0){
if(strcmp(choixdep,carte->dep)==0){
return 1;
}
}
correspondcarte(choixville, choixdep, carte.suivant);
}
//ajouter ===============================================================================================
void choix(Maillon *tville[], int nbville, char choixville[], char choixdep[]){
int i, ok;
printf("ville : \n");
fgets(choixville, 31, stdin); fgets(choixville, 31, stdin);
choixville[strlen(choixville)-1]='\0'; choixville[strlen(choixville)-1]='\0';
printf("departement : \n");
fgets(choixdep, 31, stdin); fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0'; choixdep[strlen(choixdep)-1]='\0';
ok = correspond(tville, nbville, choixville, choixdep); ok = correspondville(choixville, choixdep, tville[i], nbville);
while(ok=-1){ while(ok!=1){
affichageville(tville); printf("ville : \n");
printf("ville : ");
fgets(choixville, 31, stdin); fgets(choixville, 31, stdin);
choixville[strlen(choixville)-1]='\0'; choixville[strlen(choixville)-1]='\0';
printf("departement : \n");
fgets(choixdep, 31, stdin); fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0'; choixdep[strlen(choixdep)-1]='\0';
ok = correspond(tville, nbville, choixville, choixdep); ok = correspondville(choixville, choixdep, tville[i], nbville);
}
}
int verifdoublon(char choixville[], char choixdep[], Maillonchoix* b){
if(b==NULL){return 0;}
if(strcmp(choixville,b->Ville)==0){
if(strcmp(choixdep,b->departement)==0){
return -1
}
} }
} }
@ -203,32 +222,116 @@ int allajoutprocess(Maillon *tville[], listetuinfo etu, int nbville){
Listchoixdept b; Listchoixdept b;
b = etu.carte; b = etu.carte;
char choixville[31], choixdep[31]; char choixville[31], choixdep[31];
affichechoix(tville, nbville, choixville, choixdep); afficheville(tville, nbville);
ok = verifdoublon(choixville, choixdep, b); choix(tville, nbville, choixville, choixdep);
ok = correspondcarte(choixville, choixdep, b);
if(ok==0){b = ajoutercarte(b, choixville, choixdep);} if(ok==0){b = ajoutercarte(b, choixville, choixdep);}
else{printf("\t< choix deja existant >\n");} else{printf("\t< choix deja existant >\n");}
} }
//modifier ============================================================================================== //modifier ==============================================================================================
// modification par ville ou par dep void choix2(Listchoixdept lcarte, char choixville[], char choixdep[]){
printf("ville : \n");
fgets(choixville, 31, stdin);
choixville[strlen(choixville)-1]='\0';
printf("departement : \n");
fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0';
ok = correspondcarte(choixville, choixdep, lcarte);
while(ok!=1){
printf("ville : \n");
fgets(choixville, 31, stdin);
choixville[strlen(choixville)-1]='\0';
printf("departement : \n");
fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0';
ok = correspondcarte(choixville, choixdep, lcarte);
}
}
void choixdep(char choixville[], char choixdep[], Maillon *tville[], int nbville){
int ok;
printf("\n< quel departement voulez vous choisir ? >\n==>");
fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0';
ok = correspondville(choixville, choixdep, tville[i], nbville);
while(ok!=1){
printf("\n< quel departement voulez vous choisir ? >\n==>");
fgets(choixdep, 31, stdin);
choixdep[strlen(choixdep)-1]='\0';
ok = correspondville(choixville, choixdep, tville[i], nbville);
}
}
//supprimer ============================================================================================= 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;
}
}
b->suivant = choixmodifcarte(b.suivant, choixville, choixdep);
}
//affichage ============================================================================================= int correspondvilleonly(char choixville[], Maillon ville){
Listdept b;
if(strcmp(ville->Ville,choixville)==0){
affichervillechoix(ville);
return 1;
}
}
//======================================================================================================= void modificationcarte(listetuinfo etu, Maillon *tville[], int nbville){
int i, ok;
char choixville[31], choixdep[31];
Listchoixdept lcarte;
lcarte=etu.carte;
affichagecarte(lcarte);
choix2(lcarte, choixville, choixdep);
for(i=0; i<nbville; i++){
ok = correspondvilleonly(choixville, tville[i]);
if(ok==1){
choixdep(choixville, choixdep, tville, nbville);
lcarte = choixmodifcarte(choixville, choixdep, tville, nbville);
}
else{printf("\t< choix deja existant >\n");}
}
}
//supprimer =============================================================================================
Maillonchoix suppressioncartechoix(char choixville[], char choixdep[], Maillonchoix carte){
Maillon tmp;
if(carte==NULL){return;}
if(strcmp(carte->Ville,choixville)==0){
if(strcmp(choixdep,carte->dep)==0){
tmp=carte->suivant;
free(carte);
return tmp;
}
}
suppressioncartechoix(choixville, choixdep, carte.suivant);
}
void suppcarte(listetuinfo etu,){
int i, ok;
char choixville[31], choixdep[31];
Listchoixdept lcarte;
lcarte=etu.carte;
affichagecarte(lcarte);
choix2(lcarte, choixville, choixdep);
lcarte = suppressioncartechoix(choixville, choixdep, lcarte);
}
//=======================================================================================================
// zone de test ============================================================================================ // zone de test =========================================================================================
//affiche uniquement les cartes (choix d'iut) //affiche uniquement les cartes (choix d'iut)
void affichage(Listchoixdept c){ void affichage(Listchoixdept c){

Loading…
Cancel
Save