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.
106 lines
2.1 KiB
106 lines
2.1 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "iut.h"
|
|
|
|
//Liste:
|
|
VilleIUT initialiser (void){
|
|
VilleIUT V;
|
|
V.Idept=NULL;
|
|
V.Ville=NULL;
|
|
return V;
|
|
}
|
|
|
|
Booleen testVide(VilleIUT V){
|
|
if(V.Ville==NULL) return vrai;
|
|
return faux;
|
|
}
|
|
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);}
|
|
strcpy(m->departement, departement);
|
|
m->nbP=nbP;
|
|
strcpy(m->resp,resp);
|
|
m->suivant=NULL;
|
|
if(testVide(V)){
|
|
V.Ville=m;
|
|
V.Idept=m;
|
|
}
|
|
else{
|
|
V.Idept->suivant=m;
|
|
V.Idept=m;
|
|
}
|
|
return V;
|
|
}
|
|
VilleIUT defiler(VilleIUT V){
|
|
MaillonDept *temp;
|
|
if(testVide(V)){
|
|
printf("testVide");
|
|
return V;
|
|
}
|
|
temp=V.Ville;
|
|
V.Ville=temp->suivant;
|
|
free(temp);
|
|
if(V.Ville==NULL)
|
|
V.Idept=NULL;
|
|
return V;
|
|
}
|
|
|
|
void afficher (VilleIUT V){
|
|
if(testVide(V))
|
|
return;
|
|
printf("\n%s\t",V.Ville->departement);
|
|
printf("%d\t",V.Ville->nbP);
|
|
printf("%s\t",V.Ville->resp);
|
|
V.Ville=V.Ville->suivant;
|
|
afficher(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 V;
|
|
fscanf(fe,"%s %s %d %s",&V.ville,&V.Ville->departement,&V.Ville->nbP,&V.Ville->resp);
|
|
return V;
|
|
}
|
|
|
|
void affichage (VilleIUT *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);
|
|
|
|
}
|
|
|
|
} |