modification des fichiers, mais problème chargement, à modifier

master
Nicolas BLONDEAU 2 years ago
parent 62d052f086
commit 5d7de7c1d7

@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "iut.h"
/*
void MenuAdministrateur(VilleIUT V){
char departement[30],respon[30];
int choix,nbp;
@ -65,3 +65,4 @@ void afficherE(Maillon m){
afficherE(m->suivant);
}
*/

123
iut.c

@ -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);
}
}
}*/

22
iut.h

@ -1,19 +1,19 @@
#include <stdio.h>
/**/
typedef struct liste{
char departement[30];
int nbP;
char resp[30];
struct liste *suivant;
}MaillonDept,*Maillon;
}MaillonDept, *ListeD;
typedef struct{
char ville[30];
MaillonDept *Ville;
MaillonDept *Idept;
ListeD ldept;
}VilleIUT;
//VilleIUT *tiut;
typedef enum {faux,vrai}Booleen;
@ -21,25 +21,27 @@ typedef enum {faux,vrai}Booleen;
//void MenuUtilisateur(fdhsjklfhdsjklfhdjskl);
//Menu administrateur :
/*
void MenuAdministrateur(VilleIUT V);
Maillon suppression(Maillon m,char *departement,char *responsable);
Maillon suppressionTete(Maillon m);
void afficherE(Maillon m);
*/
//recherche
//MaillonDept recherche (MaillonDept *Ville,char *departement,char *responsable);
//Liste:
VilleIUT initialiser (void);
VilleIUT Initialisation(void);
VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp);
Booleen testVide(VilleIUT V);
void afficher (VilleIUT V);
VilleIUT defiler(VilleIUT V);
VilleIUT lireVille (FILE *fe);
int chargeResultat(VilleIUT *tiut[],int taillemax);
VilleIUT lireVille(FILE *fe, int *nbDep);
MaillonDept lireDep(FILE *fe);
int chargeResultat(VilleIUT *tiut[],int tmax);
void affichage (VilleIUT *tiut[],int n);
MaillonDept Insertion(MaillonDept *m, char *departement, int nbP,char *resp);
MaillonDept InsertionTete(MaillonDept *m, char *departement, int nbP,char *resp);

@ -1,21 +1,12 @@
#include <stdio.h>
#include "iut.h"
VilleIUT Chargement(VilleIUT V){
V=initialiser();
return V;
}
int main(){
VilleIUT V;
int n;
VilleIUT *tiut[200];
V = Chargement(V);
afficher(V);
n=chargeResultat(tiut ,200);
n=(n+1)/4;
printf("%d",n);
@ -29,6 +20,6 @@ int main(){
}
if(choix==2){
printf("Menu Administrateur");
MenuAdministrateur(V);
//MenuAdministrateur(V);
}
}

@ -1,4 +1,7 @@
Grenoble Informatique 112 Dupont-Jean
Clermont Informatique 136 Simon-Carine
Aurillac Bio-Info 56 jiji
Clermont Biologie 120 Djojo
Grenoble 1
Informatique 112 Dupont-Jean
Clermont 2
Informatique 136 Simon-Carine
Biologie 120 Djojo
Aurillac 1
Bio-Info 56 jiji
Loading…
Cancel
Save