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.
102 lines
2.3 KiB
102 lines
2.3 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "iut.h"
|
|
|
|
//Fonction d'initialisation de VilleIUT --> Renvoie une liste vide
|
|
|
|
|
|
//Fonction qui teste si la liste est vide ou non, et renvoie 'Vrai si la liste est vide', sinon 'Faux'
|
|
Booleen testVide(VilleIUT V){
|
|
if(V.ville == NULL)
|
|
return vrai;
|
|
return faux;
|
|
}
|
|
|
|
|
|
int chargement(VilleIUT *tiut[],int tmax){
|
|
int i = 0, j=0;
|
|
int nbDep = 0;
|
|
VilleIUT V;
|
|
MaillonDept m;
|
|
FILE *fe;
|
|
fe=fopen("ville.don","r");
|
|
if(fe==NULL){
|
|
printf("Problème d'ouverture du fichier");
|
|
return-1;
|
|
}
|
|
V = lireVille(fe, &nbDep);
|
|
|
|
while(!feof(fe)){
|
|
tiut[i] = (VilleIUT*)malloc(sizeof(VilleIUT));
|
|
if(tiut[i]==NULL){
|
|
printf("Problème de malloc");
|
|
return -3;
|
|
}
|
|
*tiut[i] = V;
|
|
for(j = 0; j < nbDep; j++){
|
|
|
|
m = lireDep(fe);
|
|
tiut[i]->ldept = Insertion(tiut[i]->ldept, m.departement, m.nbP, m.resp);
|
|
}
|
|
V = lireVille(fe, &nbDep);
|
|
i++;
|
|
}
|
|
fclose(fe);
|
|
return i;
|
|
}
|
|
|
|
VilleIUT lireVille(FILE *fe, int *nbDep){
|
|
VilleIUT V;
|
|
V.ldept = NULL;
|
|
fscanf(fe,"%s %d", V.ville, nbDep);
|
|
return V;
|
|
}
|
|
|
|
MaillonDept lireDep(FILE *fe){
|
|
MaillonDept m;
|
|
fscanf(fe,"%s %d %s", m.departement, &m.nbP, m.resp);
|
|
return m;
|
|
}
|
|
|
|
ListeD InsertionTete(ListeD ld, char *departement, int nbP,char *resp){
|
|
MaillonDept *m;
|
|
m = (MaillonDept*)malloc(sizeof(MaillonDept));
|
|
if(m==NULL){
|
|
printf("Problème malloc m");
|
|
exit(1);}
|
|
strcpy(m->departement, departement);
|
|
m->nbP = nbP;
|
|
strcpy(m->resp, resp);
|
|
m->suivant = ld;
|
|
return m;
|
|
}
|
|
|
|
ListeD Insertion(ListeD ld, char *departement, int nbP,char *resp){
|
|
if(ld==NULL)
|
|
return InsertionTete(ld, departement, nbP, resp);
|
|
if(strcmp(ld->departement, departement)<0)
|
|
return InsertionTete(ld, departement, nbP, resp);
|
|
ld->suivant = Insertion(ld->suivant, departement, nbP, resp);
|
|
return ld;
|
|
}
|
|
|
|
|
|
|
|
|
|
void affichage (VilleIUT *tiut[],int n){
|
|
int i;
|
|
for(i=0;i<n;i++){
|
|
printf("\n%s\n", tiut[i]->ville);
|
|
affichageListe(tiut[i]->ldept);
|
|
}
|
|
}
|
|
|
|
void affichageListe(ListeD ld){
|
|
while(ld!=NULL){
|
|
printf("%s\t",ld->departement);
|
|
printf("%d\t",ld->nbP);
|
|
printf("%s\n",ld->resp);
|
|
ld = ld->suivant;}
|
|
}
|