You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.4 KiB

#include "SAE.h"
/*
ListeDept chargeListeDept(VilleIUT *tiut[])
{
int i = 0;
ListeDept liste = listenouv();
FILE *file = fopen("informationsIUT.txt", "r");
while (!feof(file))
{
}
}*/
int chargementVillesIUT(VilleIUT *tiut[])
{
FILE *file = fopen("informationsIUT.txt", "r");
char ville[30], dept[30], resp[30];
int nbP, i = 0, insertPos;
bool trouve;
if (file == NULL)
{
printf("Fonction chargementVillesIUT : Problème lors de l'ouverture du fichier informationsIUT.txt");
exit(-1);
}
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';
insertPos = rechercheVille(tiut, i, ville, &trouve);
if (trouve == 0)
{
tiut[i] = (VilleIUT *)malloc(sizeof(VilleIUT));
if (tiut[i] == NULL)
{
printf("Fonction chargementVillesIUT : Problème lors du malloc");
exit(-1);
}
strcpy(tiut[i]->ville, ville);
tiut[i]->ldept = listenouv();
tiut[i]->ldept = inserer(tiut[i]->ldept, dept, nbP, resp);
i++;
}
else
{
tiut[insertPos]->ldept = inserer(tiut[insertPos]->ldept, dept, nbP, resp);
}
}
fclose(file);
return i;
}
int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve)
{
int i;
for (i = 0; i < nb; i++)
{
if (strcmp(tiut[i]->ville, val) == 0)
{
*trouve = true;
return i;
}
}
*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);
}