|
|
|
@ -3,19 +3,85 @@
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "iut.h"
|
|
|
|
|
|
|
|
|
|
//Liste:
|
|
|
|
|
VilleIUT initialiser (void){
|
|
|
|
|
//Fonction d'initialisation de VilleIUT --> Renvoie une liste vide
|
|
|
|
|
VilleIUT Initialisation(void){
|
|
|
|
|
VilleIUT V;
|
|
|
|
|
V.Idept=NULL;
|
|
|
|
|
V.Ville=NULL;
|
|
|
|
|
V.ldept = NULL;
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
if(V.ville == NULL)
|
|
|
|
|
return vrai;
|
|
|
|
|
return faux;
|
|
|
|
|
}
|
|
|
|
|
VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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] = Initialisation();
|
|
|
|
|
*tiut[i] = V;
|
|
|
|
|
for(j = 0; j < nbDep; j++){
|
|
|
|
|
*m = lireDep(fe);
|
|
|
|
|
tiut[i] = Insertion(m,m->departement, m->nbP, m->resp);
|
|
|
|
|
}
|
|
|
|
|
V = lireVille(fe, &nbDep);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
fclose(fe);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VilleIUT lireVille(FILE *fe, int *nbDep){
|
|
|
|
|
VilleIUT V;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaillonDept InsertionTete(MaillonDept *m, char *departement, int nbP,char *resp){
|
|
|
|
|
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);
|
|
|
|
|
return *m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaillonDept Insertion(MaillonDept *m, char *departement, int nbP,char *resp){
|
|
|
|
|
if(m==NULL)
|
|
|
|
|
return InsertionTete(m, departement, nbP, resp);
|
|
|
|
|
if(strcmp(m->departement, departement)<0)
|
|
|
|
|
return InsertionTete(m, departement, nbP, resp);
|
|
|
|
|
m->suivant = Insertion(m->suivant, departement, nbP, resp);
|
|
|
|
|
return *m;
|
|
|
|
|
}
|
|
|
|
|
/*VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp){
|
|
|
|
|
MaillonDept *m;
|
|
|
|
|
m=(MaillonDept*)malloc(sizeof(MaillonDept));
|
|
|
|
|
if(m==NULL){printf("pb ouv malloc");exit(1);}
|
|
|
|
@ -33,6 +99,8 @@ VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp){
|
|
|
|
|
}
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VilleIUT defiler(VilleIUT V){
|
|
|
|
|
MaillonDept *temp;
|
|
|
|
|
if(testVide(V)){
|
|
|
|
@ -61,46 +129,25 @@ void afficher (VilleIUT V){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int chargeResultat(VilleIUT *tiut[],int taillemax){
|
|
|
|
|
int i=0,m;
|
|
|
|
|
FILE *fe;
|
|
|
|
|
fe=fopen("ville.don","r");
|
|
|
|
|
if(fe==NULL){printf("pb ouv");return-1;}
|
|
|
|
|
VilleIUT V;
|
|
|
|
|
V=lireVille(fe);
|
|
|
|
|
|
|
|
|
|
while(!feof(fe)){
|
|
|
|
|
if(i==taillemax){
|
|
|
|
|
printf("pb de place");
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
tiut[i]=(VilleIUT*)malloc(sizeof(VilleIUT));
|
|
|
|
|
if(tiut[i]==NULL){
|
|
|
|
|
printf("pb de malloc");
|
|
|
|
|
return -3;
|
|
|
|
|
}
|
|
|
|
|
*tiut[i]=V;
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
V=lireVille(fe);
|
|
|
|
|
}
|
|
|
|
|
fclose(fe);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VilleIUT lireVille (FILE *fe){
|
|
|
|
|
|
|
|
|
|
VilleIUT lireVille(FILE *fe, int *nbDep){
|
|
|
|
|
VilleIUT V;
|
|
|
|
|
fscanf(fe,"%s %s %d %s",&V.ville,&V.Ville->departement,&V.Ville->nbP,&V.Ville->resp);
|
|
|
|
|
fscanf(fe,"%s %d", V.ville, nbDep);
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void affichage (VilleIUT *tiut[],int n){
|
|
|
|
|
MaillonDept lireDep(FILE *fe){
|
|
|
|
|
MaillonDept m;
|
|
|
|
|
fscanf(fe,"%s %d %s", m.departement, m.nbP, m.resp);
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void affichage (int *tiut[],int n){
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<n;i++){
|
|
|
|
|
printf("aaa\n");
|
|
|
|
|
//ici error
|
|
|
|
|
printf("%s %s %d %s", tiut[i]->ville, tiut[i]->Ville->departement, tiut[i]->Ville->nbP, tiut[i]->Ville->resp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}*/
|