chgt pt2 ok

master
lolax 2 years ago
parent 4c42b4837a
commit ea18d64e4b

@ -24,6 +24,18 @@ Choix lirechx (void){//Fonction qui va lire les choix de la ville et du departem
} }
Choix lireC(FILE *fe)
{
Choix c;
fscanf(fe, "%s%*c", c.ville);
fgets(c.dptmt, 26, fe);
c.dptmt[strlen(c.dptmt)-1]= '\0';
fscanf(fe, "%d %d%*c", &c.dec, &c.valid);
printf("J'ai bien été scanné\n");
return c;
}
Candidat lireCandidat(void)//fonction qui lit un candidat sur le clavier Candidat lireCandidat(void)//fonction qui lit un candidat sur le clavier
{ {
@ -51,42 +63,58 @@ Candidat lireCandidat(void)//fonction qui lit un candidat sur le clavier
} }
Candidat lireCa(FILE *fe)
{
Candidat c;//candidat que l'on retournera
Choix chx;//pour la création de maillons
int cpt = 0;//qui servira à compter le nombre de choix
fscanf(fe,"%d", c.nEtu);
fgets(c.nom, 23, fe);
c.nom[strlen(c.nom)-1]= '\0';
fgets(c.prenom, 23, fe);
c.prenom[strlen(c.prenom)-1]= '\0';
fscanf(fe, "%f %f %f %f %d%*c", c.moymat, c.moyfr, c.moyen, c.moyspe, c.nbchx);
c.lchx = NULL;//initialisation de la liste
return c;
}
/*
Choix * chargeChoix(Choix *tchoix, TAILLE, nbchx){
Listechx InsertTC(Listechx list, Maillonchx m)//Insert en tête de la liste
{
Maillonchx *mchx;
mchx = (Maillonchx*)malloc(sizeof(Maillonchx));
if (mchx == NULL){printf("pb malloc"); exit(-1);}
mchx->chx = m.chx;
mchx->suivchx = list;
return mchx;
} }
*/
Listechx InsertC(Listechx list, Maillonchx m)//insert globalement dans liste de choix
{
if (list == NULL){return InsertTC(list, m);}
if (strcmp(list->chx.dptmt, m.chx.dptmt)>0){return InsertTC(list, m);}
list->suivchx = InsertC(list->suivchx, m);
return list;
}
void AffC(Candidat c) void AffC(Candidat c)
{ {
printf("%d", c.nEtu); printf("%d\n", c.nEtu);
printf("%s \n %s\n", c.nom, c.prenom); printf("%s\n%s\n", c.nom, c.prenom);
printf("%.2f\t%.2f\t%.2f\t%.2f\n", c.moymat,c.moyfr, c.moyen, c.moyspe); printf("%.2f\t%.2f\t%.2f\t%.2f\n", c.moymat,c.moyfr, c.moyen, c.moyspe);
printf("%d\n", c.nbchx); printf("%d\n", c.nbchx);
} }
void AffCh(Choix c)
Candidat lireFich1Cand (FILE * fe){ {
Candidat cand; printf("%s \n", c.ville);
printf("%s \n", c.dptmt);
fgets(cand.nom, 20, fe); printf("%d \n", c.dec);
cand.nom[strlen(cand.nom)-1]= '\0'; printf("%d \n", c.valid);
fgets(cand.prenom, 20, fe);
cand.prenom[strlen(cand.prenom)-1]= '\0';
fscanf(fe, "%f", &cand.moymat);
fscanf(fe, "%f", &cand.moyfr);
fscanf(fe, "%f", &cand.moyen);
fscanf(fe, "%f", &cand.moyspe);
fscanf(fe, "%d%*c", &cand.nbchx);
return cand;
} }
//######################################### LISTES ########################################## //######################################### LISTES ##########################################
@ -95,11 +123,21 @@ Candidat lireFich1Cand (FILE * fe){
void AffListeCandidat (Listecand l){ void AffListeCandidat (Listecand l){
if ( l == NULL) return; if (l == NULL) return;
AffC(l->cand); AffC(l->cand);
if (l->cand.lchx == NULL){printf("whybitch");}
AffListChoix(l->cand.lchx);
AffListeCandidat(l->suivcand); AffListeCandidat(l->suivcand);
} }
void AffListChoix(Listechx l)
{
if (l == NULL) return;
AffCh(l->chx);
AffListChoix(l->suivchx);
}
Listecand recherchenom (Listecand l, char *nom ){ Listecand recherchenom (Listecand l, char *nom ){
if ( l == NULL ){ return l;} if ( l == NULL ){ return l;}
if ( strcmp ( l->cand.nom, nom ) == 0) return l; if ( strcmp ( l->cand.nom, nom ) == 0) return l;
@ -118,6 +156,7 @@ Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste
c1 = (Mailloncand*)malloc(sizeof(Mailloncand)); c1 = (Mailloncand*)malloc(sizeof(Mailloncand));
if (c1 == NULL){printf("pb malloc"); exit;} if (c1 == NULL){printf("pb malloc"); exit;}
c1->cand.nEtu = c.nEtu;
strcpy(c1->cand.nom, c.nom); strcpy(c1->cand.nom, c.nom);
strcpy(c1->cand.prenom, c.prenom); strcpy(c1->cand.prenom, c.prenom);
c1->cand.moymat = c.moymat; c1->cand.moymat = c.moymat;
@ -125,9 +164,9 @@ Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste
c1->cand.moyen = c.moyen; c1->cand.moyen = c.moyen;
c1->cand.moyspe = c.moyspe; c1->cand.moyspe = c.moyspe;
c1->cand.nbchx = c.nbchx; c1->cand.nbchx = c.nbchx;
c1->cand.lchx = c.lchx;
c1->suivcand = list; c1->suivcand = list;
return c1; return c1;
} }
@ -139,41 +178,51 @@ Listecand Insert(Listecand list, Candidat c)//insert globalement
return list; return list;
} }
void Chargementlistecandidat( Mailloncand *cand, char *nameFile, int *n)// fonction de chargement de la liste des candidats
{
FILE *f;
Maillon *tmp;
int n = 0, cpt, nbcand;
f = fopen(nameFile, "r");
if (f == NULL){printf("pb ouv file"); return -1;}
fscanf(f, "%d", n);
for ( int j = 0; j < = n; j++ ) Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction de chargement de la liste des candidats
{
int cpt, j;
fscanf(fe, "%d", nbC);
for (j = 1; j <= *nbC; j++)
{ {
Candidat Ca;
cand = (Mailloncand *)malloc(sizeof(Mailloncand)); fscanf(fe, "%d %s%*c", &Ca.nEtu, Ca.nom);
if (cand == NULL){printf("pb malloc");exit();} fgets(Ca.prenom, 31, fe);
Ca.prenom[strlen(Ca.prenom)-1]= '\0';
fscanf(f, " %d %s %s %f %f %f %f %d ", &cand->cand.nEtu, cand->cand.nom, cand->cand.prenom, &cand->cand.moymat, &cand->cand.moyfr, &cand->cand.moyen, &cand->cand.moyspe, &cpt); fscanf(fe,"%f %f %f %f %d%*c", &Ca.moymat, &Ca.moyfr, &Ca.moyen, &Ca.moyspe, &Ca.nbchx);
Ca.lchx=NULL;
for (cpt; cpt > 0; cpt--)
for (cpt = Ca.nbchx; cpt >= 1; cpt--)
{ {
Maillonchx *chx; printf("je passe et je marche\n");
chx = (Maillonchx*)malloc(sizeof(Maillonchx));//création du maillon Maillonchx chx;
if (chx == NULL){printf("pb malloc"); exit;} Choix c;
lireM(f, chx);//lire le maillon avec la fonction plus haut c = lireC(fe);//lire le maillon avec la fonction plus haut
chx->ldept = Insert(tmp->lchx, chx);//insert le maillon à sa bonne place chx.chx = c;//le choix du maillon est celui lu au dessus
Ca.lchx = InsertC(Ca.lchx, chx);//insert le maillon à sa bonne place
} }
i++; lC = Insert(lC, Ca);
} }
return i; return lC;
}
void testchgt(void)
{
int nbC = 0;
Listecand lC=NULL;
FILE *fe;
fe=fopen("part2.don", "r");
if (fe == NULL){printf("pb ouv file"); return;}
lC = Chargementlistecandidat(fe, lC, &nbC);
AffListeCandidat(lC);
} }
void test (void){ void test (void){
int menu1, menugest1, numet; int menu1, menugest1, numet;

@ -1,14 +1,9 @@
4 4
35 35
Durand Durand
Jean Jacques Jean Jacques
15.75 12.25 9.5 17.00 15.75 12.25 9.5 17.00
3 3
Clermont-Ferrand Clermont-Ferrand
Informatique Informatique
0 0
@ -24,13 +19,9 @@ Bio-Informatique
36 36
Dupont Dupont
Jeannine Jeannine
10.2 15.65 12.45 18.00 10.2 15.65 12.45 18.00
2 2
Clermont-Ferrand Clermont-Ferrand
Informatique Informatique
0 0
@ -42,13 +33,9 @@ Informatique
37 37
Thérèse Thérèse
Francoise Francoise
10.5 12.65 14.45 16.00 10.5 12.65 14.45 16.00
1 1
Clermont-Ferrand Clermont-Ferrand
Bio-Informatique Bio-Informatique
0 0
@ -56,13 +43,9 @@ Bio-Informatique
38 38
Henry Henry
Bertrand Bertrand
5.2 14.65 11.23 14.00 5.2 14.65 11.23 14.00
2
3
Clermont-Ferrand Clermont-Ferrand
Informatique Informatique
0 0

@ -5,7 +5,7 @@
finalité : SAE 1.02 Algorithme finalité : SAE 1.02 Algorithme
*/ */
/* /*
Brief : Brief :
*/ */
#define TAILLE 100; #define TAILLE 100;
@ -17,15 +17,15 @@ typedef struct {
int valid;//validation du candidat int valid;//validation du candidat
}Choix; }Choix;
typedef struct Liste1{
typedef struct Listchx{
Choix chx; Choix chx;
struct List1 * suivchx; struct Listchx * suivchx;
}Maillonchx; }Maillonchx;
typedef Maillonchx * Listechx; typedef Maillonchx * Listechx;
typedef struct { typedef struct {
int nEtu;//numéro d'étudiant int nEtu;//numéro d'étudiant
char nom[20];//nom de l'étudiant char nom[20];//nom de l'étudiant
@ -35,52 +35,38 @@ typedef struct {
float moyen;//moyenne en anglais float moyen;//moyenne en anglais
float moyspe;//moyenne en spécialité float moyspe;//moyenne en spécialité
int nbchx;//nombre de choix int nbchx;//nombre de choix
Choix * lchx; Listechx lchx;
}Candidat; }Candidat;
typedef struct Liste{
typedef struct Mailloncand{
Candidat cand; Candidat cand;
struct Liste * suivcand; struct Mailloncand * suivcand;
}Mailloncand; }Mailloncand;
typedef Mailloncand * Listecand; typedef Mailloncand * Listecand;
Choix lirechx (void); Choix lirechx (void);
Choix lireC(FILE *fe);
Candidat lireCandidat(void); Candidat lireCandidat(void);
Candidat lireCa(FILE *fe);
Listechx InsertTC(Listechx list, Maillonchx m);
Listechx InsertC(Listechx list, Maillonchx m);
void AffC(Candidat c); void AffC(Candidat c);
Candidat lireFich1Cand (FILE * fe); void AffCh(Choix c);
void AffListeCandidat (Listecand l); void AffListeCandidat (Listecand l);
void AffListChoix(Listechx l);
Listecand recherchenom (Listecand l, char *nom ); Listecand recherchenom (Listecand l, char *nom );
Listecand recherchenum (Listecand l, int num); Listecand recherchenum (Listecand l, int num);
Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC);
Listecand Insert(Listecand list, Candidat c);
Listecand InsertT(Listecand list, Candidat c);
void test (void); void test (void);
void testchgt(void);
void affpartonsenpete(Listecand lC, int nbC);

@ -6,6 +6,6 @@
int main(void) int main(void)
{ {
test(); testchgt();
return 0; return 0;
} }

Loading…
Cancel
Save