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.

172 lines
3.8 KiB

#include "Jsae.h"
int chargement(VilleIUT *tiut[],int tMax)
{
FILE *flot;
int tLog = 0, pos, trouve;
char nomV[31];
Departement d;
flot = fopen("IUT.don","r");
if(flot == NULL)
{
printf("Erreur lors de l'ouverture du fichier\n");
fclose(flot);
return -1;
}
fscanf(flot, "%s", nomV);
while(!feof(flot))
{
if(tLog == tMax)
{
printf("Tableau tiut plein\n");
fclose(flot);
return -3;
}
d = lireDep(flot);
pos = rechercheIUT(tiut,tLog,nomV,&trouve);
if(trouve == 1)
{
tiut[pos]->lDept = insererDept(tiut[pos]->lDept, d);
}
else
{
insererVille(tiut, nomV, d, &tLog, tMax, pos);
}
fscanf(flot, "%s", nomV);
}
fclose(flot);
return tLog;
}
Departement lireDep(FILE *flot)
{
Departement d;
fscanf(flot,"%s%d", d.dept, &d.nbP);
fgets(d.respAd,31,flot);
d.respAd[strlen(d.respAd) - 1] = '\0';
return d;
}
int insererVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos)
{
int i;
if(*tLog == tMax)
{
printf("Tableau plein, insertion impossible\n");
return -1;
}
for(i = *tLog - 1; i >= pos; i--)
tiut[i + 1] = tiut[i];
tiut[pos] = (VilleIUT *)malloc(sizeof(VilleIUT));
if(tiut[pos] == NULL)
{
printf("problème d'allocation mémoire lors de l'insertion de la ville\n");
return -1;
}
strcpy(tiut[pos]->nom, nomV);
tiut[pos]->lDept = listeDeptNouv();
tiut[pos]->lDept = insererDept(tiut[pos]->lDept,d);
*tLog = *tLog + 1;
return 0;
}
void afficherDep(Departement d)
{
printf("_____________________________________________________________________________\n");
printf("| Département |\n");
printf("|----------------------------------------------------------------------------|\n");
printf("| %-32s | %3d | %-32s |\n", d.dept, d.nbP, d.respAd);
printf("|----------------------------------------------------------------------------|\n");
}
void afficherVille(VilleIUT v)
{
printf("|----------------------------------|\n");
printf("| %-32s |\n", v.nom);
printf("|----------------------------------|\n");
}
void afficherTIUT(VilleIUT *tiut[], int tLog)
{
int i = 0;
printf("____________________________________\n");
printf("| Ville |\n");
for(i = 0; i < tLog; i++)
{
afficherVille(*tiut[i]);
}
printf("\n");
}
void afficherVilleDep(VilleIUT v)
{
ListeDept l;
printf("_________________________________________________________________________________________________________________\n");
printf("| Ville | Département |\n");
printf("|----------------------------------|----------------------------------------------------------------------------|\n");
l = v.lDept;
while(l != NULL)
{
printf("| %-32s | %-32s | %3d | %-32s |\n", v.nom, l->d.dept, l->d.nbP, l->d.respAd);
printf("|----------------------------------|----------------------------------------------------------------------------|\n");
l = l->suiv;
}
}
int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve)
{
int inf,sup,t;
inf = 0;
sup = tLog - 1;
printf("Ville recherchée : %s\n", ville);
while(inf <= sup)
{
t = (inf + sup) / 2;
if(strcmp(ville, tiut[t]->nom) == 0)
{
*trouve = 1;
return t;
}
if(strcmp(ville, tiut[t]->nom) < 0)
{
sup = t - 1;
}
else
{
inf = t + 1;
}
}
*trouve = 0;
return inf;
}
void globale(void)
{
int tLog, retour;
VilleIUT *tiut[100];
if(tiut == NULL)
{
printf("Problème d'allocation mémoire du tableau tiut\n");
exit(1);
}
tLog = chargement(tiut,100);
if(tLog < 0)
{
printf("Le programme ne peut pas fonctionner\n");
exit(1);
}
retour = login();
while(retour != -1)
{
if(retour == 1)
{
menuAdmin(tiut, &tLog, 100);
}
if(retour == 0)
{
menuCandidat(tiut, &tLog, 100);
}
retour = login();
}
}