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.
220 lines
5.2 KiB
220 lines
5.2 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();
|
|
}
|
|
}
|
|
|
|
void miseAJourPlaces(VilleIUT *tiut[], int tLog)
|
|
{
|
|
int trouve, pos, places;
|
|
char ville[31], dept[31], choix;
|
|
ListeDept l;
|
|
printf("Dans quelle ville se situe le département concerné ?\nSaisie : ");
|
|
scanf("%s%*c", ville);
|
|
printf("\n");
|
|
pos = rechercheIUT(tiut, tLog, ville, &trouve);
|
|
while(trouve == 0)
|
|
{
|
|
printf("Cette ville n'existe pas, veuillez re-saisir : ");
|
|
scanf("%s%*c", ville);
|
|
printf("\n");
|
|
pos = rechercheIUT(tiut, tLog, ville, &trouve);
|
|
}
|
|
l = tiut[pos]->lDept;
|
|
printf("Quel département souhaitez-vous mettre à jour ?\nSaisie : ");
|
|
scanf("%s%*c", dept);
|
|
printf("\n");
|
|
l = rechercherDept(l, dept, &trouve);
|
|
while(trouve == 0)
|
|
{
|
|
printf("Ce département n'existe pas, veuillez-resaisir : ");
|
|
scanf("%s%*c", dept);
|
|
printf("\n");
|
|
l = rechercherDept(l, dept, &trouve);
|
|
}
|
|
printf("Vous avez sélectionné le département %s dans la ville de %s.\nSouhaitez-vous continuez ? (O/N)\nSaisie : ", dept, ville);
|
|
scanf("%c%*c", &choix);
|
|
printf("\n");
|
|
if(choix == 'N')
|
|
{
|
|
return;
|
|
}
|
|
printf("Il y a actuellement %d places.\nQuel est le nouveau nombre de places ?\nSaisie : ", l->d.nbP);
|
|
scanf("%d%*c", &places);
|
|
printf("\nVous avez saisie %d places, veuillez confirmez (O/N)\nSaisie : ", places);
|
|
scanf("%c%*c", &choix);
|
|
printf("\n");
|
|
if(choix == 'O')
|
|
{
|
|
l->d.nbP = places;
|
|
printf("La mise à jour a bien été effectuée.\n");
|
|
}
|
|
return;
|
|
} |