diff --git a/SAEl.c b/SAEl.c index bdff3d9..334ee9a 100644 --- a/SAEl.c +++ b/SAEl.c @@ -169,18 +169,102 @@ bool vide(ListeDept l) return true; // 1 return false; // 0 } -/* -int longueur(ListeDept l) + +int longueurListe(ListeDept l) { int cpt = 0; while (l != NULL) { - cpt + 1; + cpt += 1; l = l->suiv; } return cpt; } -*/ + +void SauvegarderIUT(VilleIUT** tabV, int tailleL) { + int i; + FILE* flot; + flot = fopen("iut.txt","w"); + for (i = 0 ; i < tailleL ; i++) { + fprintf(flot,"%s\n",tabV[i]->ville); + fprintf(flot,"%d\n",longueurListe(tabV[i]->idDept)); + SauvegarderListe(tabV[i]->idDept,flot); + free(tabV[i]); + } +} + +void SauvegarderListe(ListeDept l, FILE* flot) { + MaillonDept* tmp; + while (l->suiv != NULL) { + tmp = l; + fprintf(flot,"%s %d %s\n",l->departement,l->nbPlaces,l->nom); + l = l->suiv; + free(tmp); + } + fprintf(flot,"%s %d %s\n",l->departement,l->nbPlaces,l->nom); + free(l); + +} + + +void creationDept(VilleIUT **tiut, int nbEle) +{ + MaillonDept *aux; + char code[30], nom[30]; + int trouve, pos, nbP; + while(1) + { + printf("Dans quel IUT voulez-vous créer un département : "); + scanf("%s", code); + pos = rechVille(tiut, nbEle, code, &trouve); + if (trouve == 1) + { + while(1) + { + printf("Nom du Département : "); + scanf("%s", code); + aux = rechercheDept(tiut[pos]->idDept, code); + if (aux != NULL) + printf("Département déjà existant"); + if (aux == NULL) + { + printf("Nom du Responsable du Département de %s : ",code); + fgets(nom,30,stdin); + nom[strlen(nom)-1] = '\0'; + printf("Nombre de place du Département %s : ",code); + scanf("%d", nbP); + tiut[pos]->idDept = insererDept(tiut[pos]->idDept,code,nom,nbP); + printf("insertion du département %s effectuer \n", code); + } + printf("Saisi Département :\n"); + if (!verifSelection()) + break; + } + } + if (trouve == 0) + printf("Cet ville n'a pas d'IUT\n"); + printf("Saisi Ville :\n"); + if(!verifSelection()) + break; + + } + +} + +bool verifSelection(void) +{ + char choix[4]; + while(1) + { + printf("Voulez-vous continué la sélection (oui|non) : "); + scanf("%s",choix); + if (strcmp(choix,"oui")==0) + return true; + if (strcmp(choix,"non")==0) + return false; + printf("Erreur de sélection ! Veuillez réessayer \n"); + } +} ListeDept rechercheDept(ListeDept l, char code[]) { @@ -193,6 +277,23 @@ ListeDept rechercheDept(ListeDept l, char code[]) return rechercheDept(l->suiv, code); } +int rechVille(VilleIUT **tiut, int nbEle, char code[], int *trouve) +{ + int inf = 0, sup = nbEle - 1, m; + while(inf <= sup) + { + m = (inf + sup)/2; + if (strcmp(tiut[m]->ville, code)==0) + { + *trouve = 1; + return m; + } + if (strcmp(tiut[m]->ville, code)>0) + sup = m - 1; + else inf = m + 1; + } +} + /* ListeDept ajouterEnQueue(ListeDept l, int x) { diff --git a/SAEl.h b/SAEl.h index ca4db57..bdf3a32 100644 --- a/SAEl.h +++ b/SAEl.h @@ -35,3 +35,14 @@ VilleIUT** chargementVille(char* nomFich, int tphys, int* tailleL); ListeDept supprimerDept(ListeDept l, char *code); +int longueurListe(ListeDept l); + +void SauvegarderIUT(VilleIUT** tabV, int tailleL); + +void SauvegarderListe(ListeDept l, FILE* flot); + +bool verifSelection(void); + +void creationDept(VilleIUT **tiut, int nbEle); + +int rechVille(VilleIUT **tiut, int nbEle, char code[], int *trouve); \ No newline at end of file diff --git a/iut.txt b/iut.txt index a1dd15a..bad4ce0 100644 --- a/iut.txt +++ b/iut.txt @@ -5,4 +5,6 @@ Réseaux 5 Unmec Sympa Lyon 2 Jeux-videos 24 Kojima Hideo -GEA 8 Macron Emmanuel +GEA 8 Marx Karl + + diff --git a/testSAE.c b/testSAE.c index 261052c..ee46a11 100644 --- a/testSAE.c +++ b/testSAE.c @@ -6,13 +6,13 @@ void globale(void) { VilleIUT** tab; char nomFich[20]; strcpy(nomFich,"iut.txt"); - printf("charg\n"); tab = chargementVille(nomFich,30,&tailleL); - printf("affich\n"); for(i = 0 ; i < tailleL ; i++) { printf("Ville : %s\n",tab[i]->ville); affichageListeDept(tab[i]->idDept); } + creationDept(tab,tailleL); + SauvegarderIUT(tab,tailleL); } int main(void) {