Ajout de la fonction de sauvegarde

master
Kyllian Chabanon 2 years ago
parent 0bc63869ee
commit 898187040b

@ -1,4 +1,4 @@
Grenoble Informatique 112 Dupont Jean
Clermont-Ferrand Biologie 120 Coralie Elebon
Clermont-Ferrand Informatique 136 Simon Carine
Aurillac Bio-Informatique 56 Ayoub Milaki
Clermont-Ferrand Biologie 120 Coralie Elebone

@ -26,8 +26,9 @@ int chargementVillesIUT(VilleIUT *tiut[])
while (!feof(file))
{
fscanf(file, "%s%s%d", ville, dept, &nbP);
fseek(file, 1, SEEK_CUR);
fgets(resp, 30, file);
resp[strlen(resp) -1] = '\0';
resp[strlen(resp) - 1] = '\0';
insertPos = rechercheVille(tiut, i, ville, &trouve);
if (trouve == 0)
@ -68,3 +69,28 @@ int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve)
*trouve = false;
return i;
}
void sauvegarde(VilleIUT *tiut[], int nb)
{
char ville[30], dept[30], resp[30];
int nbP, posDept;
FILE *file = fopen("informationsIUT.txt", "w");
if (file == NULL)
{
printf("Fonction sauvegarde : Problème lors de l'ouverture du fichier informationsIUT.txt");
exit(-1);
}
for (int i = 0; i < nb; i++)
{
strcpy(ville, tiut[i]->ville);
while (!vide(tiut[i]->ldept))
{
strcpy(dept, getDept(tiut[i]->ldept, 0));
nbP = getNbP(tiut[i]->ldept, 0);
strcpy(resp, getResp(tiut[i]->ldept, 0));
fprintf(file, "%s %s %d %s\n", ville, dept, nbP, resp);
tiut[i]->ldept = supprimerEnTete(tiut[i]->ldept);
}
}
fclose(file);
}

@ -7,6 +7,7 @@
/* Fichier */
int chargementVillesIUT(VilleIUT *tiut[]);
int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve);
void sauvegarde(VilleIUT *tiut[], int nb);
/* Utilisateur */
void affichageVillesIUT(VilleIUT *tiut[], int nb);

@ -155,3 +155,12 @@ void setResp(ListeDept l, int pos, char valeur[])
}
strcpy(l->resp, valeur);
}
char* getDept(ListeDept l, int pos)
{
for (int i = 0; i < pos; i++)
{
l = l->suiv;
}
return l->departement;
}

@ -30,3 +30,5 @@ int getNbP(ListeDept l, int pos);
void setNbP(ListeDept l, int pos, int valeur);
char* getResp(ListeDept l, int pos);
void setResp(ListeDept l, int pos, char valeur[]);
char* getDept(ListeDept l, int pos);
void setResp(ListeDept l, int pos, char valeur[]);

@ -10,7 +10,8 @@ int main(void)
// modificationNbPDept(tiut, nbVilles);
// creationDept(tiut, nbVilles);
// nbVilles = suppressionDept(tiut, nbVilles);
modificationRespDept(tiut, nbVilles);
affichageDeptIUT(tiut, nbVilles);
//modificationRespDept(tiut, nbVilles);
//affichageDeptIUT(tiut, nbVilles);
sauvegarde(tiut, nbVilles);
return 0;
}

Loading…
Cancel
Save