plusieurs fonctions monter dans test part2

master
Roxane ROSSETTO 2 years ago
parent 6beed8639d
commit 4cacef5677

@ -28,11 +28,14 @@ Choix lirechx (void){//Fonction qui va lire les choix de la ville et du departem
Candidat lireCandidat(void)//fonction qui lit un candidat sur le clavier
{
Candidat c;
printf("Veuillez entrer votre numéro de Candidat");
scanf("%d%*c", &c.nEtu );
printf("Nom du candidat :\n");
fgets(c.nom, 20, stdin);
fgets(c.nom, 23, stdin);
c.nom[strlen(c.nom)-1]= '\0';
printf("Prénom du candidat :\n");
fgets(c.prenom, 20, stdin);
fgets(c.prenom, 23, stdin);
c.prenom[strlen(c.prenom)-1]= '\0';
printf("Moyenne de maths :\n");
scanf("%f", &c.moymat);
@ -61,6 +64,7 @@ Choix * chargeChoix(Choix *tchoix, TAILLE, nbchx){
void AffC(Candidat c)
{
printf("%d", c.nEtu);
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("%d\n", c.nbchx);
@ -96,10 +100,16 @@ void AffListeCandidat (Listecand l){
AffListeCandidat(l->suivcand);
}
Listecand recherche (Listecand l, char *nom ){
Listecand recherchenom (Listecand l, char *nom ){
if ( l == NULL ){ return l;}
if ( strcmp ( l->cand.nom, nom ) == 0) return l;
return recherche (l->suivcand, nom );
return recherchenom (l->suivcand, nom );
}
Listecand recherchenum (Listecand l, int num){
if ( l == NULL ){ return l;}
if ( l->cand.nEtu == num ) return l;
return recherchenum (l->suivcand, num );
}
Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste
@ -121,20 +131,56 @@ Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste
}
Listecand Insert(Listecand list, Mailloncand * c)//insert globalement
Listecand Insert(Listecand list, Candidat c)//insert globalement
{
if (list == NULL){return InsertT(list, c);}
if (strcmp(list->departement, m->departement)>0){return InsertT(list, m);}
list->suiv = Insert(list->suiv, m);
if (strcmp(list->cand.nom, c.nom)>0){return InsertT(list, c);}
list->suivcand = Insert(list->suivcand, c);
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++ )
{
cand = (Mailloncand *)malloc(sizeof(Mailloncand));
if (cand == NULL){printf("pb malloc");exit;}
fscanf(f, " %d %s %s %.2f %.2f %.2f %.2f %d ", &cand->cand.nEtu, cand->cand.nom, cand->cand.prenom, &cand->cand.moymat, &cand->cand.moyfr, &cand->cand.moyen, &cand->cand.moyspe, &cpt);
for (cpt; cpt > 0; cpt--)
{
Maillonchx *chx;
chx = (Maillonchx*)malloc(sizeof(Maillonchx));//création du maillon
if (chx == NULL){printf("pb malloc"); exit;}
lireM(f, chx);//lire le maillon avec la fonction plus haut
chx->ldept = Insert(tmp->lchx, chx);//insert le maillon à sa bonne place
}
tV[i] = v;
i++;
}
return i;
}
void test (void){
int menu1, menugest1;
int menu1, menugest1, numet;
Candidat cand1;
Listecand lcand, l2cand;
printf("Menu :\n");//Premier affichage menu pour choisir si on veut afficher le menu d'un candidat ou toutes les candidatures
@ -155,9 +201,20 @@ void test (void){
printf("(1) Ajouter une Candidature\n (2) Modifier une Candidature\n (3) Supprimer une Candidature");
scanf("%d", &menugest1);
if (menugest1 == 1)
//FONCTION INSERTION LISTE AVEC AFFICHAGE NOUVELLE LISTE
//else if (menugest1 == 2)
if (menugest1 == 1){
printf("Veuillez renseigner votre numéro d'étudiant\n");
scanf("%d", &numet);
l2cand = recherchenum( lcand, numet);
AffListeCandidat(l2cand);
cand1 = lireCandidat();
lcand = Insert(lcand , cand1);
AffListeCandidat(lcand);
}
//else if (menugest1 == 2)
//FONCTION MISE A JOUR LISTE AVEC AFFICHAGE NOUVELLE LISTE
//else if (menugest1 == 3)
//FONCTION SUPPRESSION LISTE AVEC AFFICHAGE NOUVELLE LISTE

@ -11,7 +11,6 @@
typedef struct {
int nEtu;//numéro d'étudiant
char ville[20];//ville choisie
char dptmt[20];//département choisi
int dec;//décision du choix
@ -28,6 +27,7 @@ typedef Maillonchx * Listechx;
typedef struct {
int nEtu;//numéro d'étudiant
char nom[20];//nom de l'étudiant
char prenom[20];//prénom de l'étudiant
float moymat;//moyenne en maths
@ -52,7 +52,8 @@ Candidat lireCandidat(void);
void AffC(Candidat c);
Candidat lireFich1Cand (FILE * fe);
void AffListeCandidat (Listecand l);
Listecand recherche (Listecand l, char *nom );
Listecand recherchenom (Listecand l, char *nom );
Listecand recherchenum (Listecand l, int num);
void test (void);

BIN
test

Binary file not shown.
Loading…
Cancel
Save