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.
91 lines
1.6 KiB
91 lines
1.6 KiB
#include "Jsae.h"
|
|
|
|
int chargement(VilleIUT *tiut[],int *tMax)
|
|
{
|
|
FILE *flot;
|
|
VilleIUT *v;
|
|
MaillonDept *m;
|
|
int nb = 0, pos;
|
|
char trouve;
|
|
flot = fopen("IUT.don", "r");
|
|
if(flot == NULL)
|
|
{
|
|
printf("Problème d'ouverture du fichier\n");
|
|
return -1;
|
|
}
|
|
while(!feof(flot))
|
|
{
|
|
v = (VilleIUT *)malloc(sizeof(VilleIUT));
|
|
if(v == NULL)
|
|
{
|
|
printf("Problème allocation ville lors de la lecture du fichier\n");
|
|
return -2;
|
|
}
|
|
fscanf(flot, "%s", v->nom);
|
|
pos = recherche(tiut, nb, v->nom, &trouve);
|
|
m = (MaillonDept *)malloc(sizeof(MaillonDept));
|
|
if(m == NULL)
|
|
{
|
|
printf("Problème allocation département lors de la lecture du fichier\n");
|
|
return -3;
|
|
}
|
|
*m = lireDep(flot);
|
|
if(trouve == 'O')
|
|
{
|
|
insererDep(tiut[pos],*m);
|
|
}
|
|
else
|
|
{
|
|
m->suiv = NULL;
|
|
v->lDept = m;
|
|
tiut[nb] = v;
|
|
}
|
|
free(v);
|
|
free(m);
|
|
nb++;
|
|
}
|
|
return nb;
|
|
}
|
|
|
|
MaillonDept lireDep(FILE *flot)
|
|
{
|
|
MaillonDept m;
|
|
fscanf(flot,"%s%d", m.dept, &m.nbP);
|
|
fgets(m.respAd,31,flot);
|
|
m.respAd[strlen(m.respAd) - 1] = '\0';
|
|
return m;
|
|
}
|
|
|
|
void afficherDep(MaillonDept m)
|
|
{
|
|
printf("%s\t%d\t%s\n", m.dept, m.nbP, m.respAd);
|
|
}
|
|
|
|
void afficherVille(VilleIUT v)
|
|
{
|
|
printf("%s\t", v.nom);
|
|
while(v.lDept != NULL)
|
|
{
|
|
afficherDep(*v.lDept);
|
|
v.lDept = v.lDept->suiv;
|
|
}
|
|
}
|
|
|
|
|
|
void globale(void)
|
|
{
|
|
int tLog, tMax = 10;
|
|
VilleIUT **tiut;
|
|
tiut = (VilleIUT **)malloc(sizeof(VilleIUT *) * 10);
|
|
if(tiut == NULL)
|
|
{
|
|
printf("Problème d'allocation mémoire du tableau tiut\n");
|
|
exit(1);
|
|
}
|
|
tLog = chargement(tiut,&tMax);
|
|
if(tLog < 0)
|
|
{
|
|
printf("Le programme ne peut pas fonctionner\n");
|
|
exit(1);
|
|
}
|
|
} |