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.

270 lines
5.5 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "part2.h"
//##########################TABLEAU POINTEUR#####################################################
Choix lirechx (void){//Fonction qui va lire les choix de la ville et du departement demandé par le candidat
Choix chx;
printf("Saisir le choix de la ville \n");
fgets(chx.ville, 20, stdin);
chx.ville[strlen(chx.ville)-1]= '\0';
printf("Saisir le choix du departement d'étude\n");
fgets(chx.dptmt, 20, stdin);
chx.dptmt[strlen(chx.dptmt)-1]= '\0';
chx.dec = 0;
chx.valid = 0;
return chx;
}
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, 23, stdin);
c.nom[strlen(c.nom)-1]= '\0';
printf("Prénom du candidat :\n");
fgets(c.prenom, 23, stdin);
c.prenom[strlen(c.prenom)-1]= '\0';
printf("Moyenne de maths :\n");
scanf("%f", &c.moymat);
printf("Moyenne de français :\n");
scanf("%f", &c.moyfr);
printf("Moyenne d'anglais :\n");
scanf("%f", &c.moyen);
printf("Moyenne de spécialité au choix :\n");
scanf("%f", &c.moyspe);
printf("Nombre de choix :\n");
scanf("%d%*c", &c.nbchx);
return c;
}
/*
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);
}
Candidat lireFich1Cand (FILE * fe){
Candidat cand;
fgets(cand.nom, 20, fe);
cand.nom[strlen(cand.nom)-1]= '\0';
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 ##########################################
void AffListeCandidat (Listecand l){
if ( l == NULL) return;
AffC(l->cand);
AffListeCandidat(l->suivcand);
}
Listecand recherchenom (Listecand l, char *nom ){
if ( l == NULL ){ return l;}
if ( strcmp ( l->cand.nom, nom ) == 0) return l;
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
{
Mailloncand *c1;
c1 = (Mailloncand*)malloc(sizeof(Mailloncand));
if (c1 == NULL){printf("pb malloc"); exit;}
strcpy(c1->cand.nom, c.nom);
strcpy(c1->cand.prenom, c.prenom);
c1->cand.moymat = c.moymat;
c1->cand.moyfr = c.moyfr;
c1->cand.moyen = c.moyen;
c1->cand.moyspe = c.moyspe;
c1->cand.nbchx = c.nbchx;
c1->suivcand = list;
return c1;
}
Listecand Insert(Listecand list, Candidat c)//insert globalement
{
if (list == NULL){return InsertT(list, c);}
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, 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
printf("(1) Gestion Candidature\n(2) Affichage Candidature\n");
scanf("%d", &menu1);
printf("%d", menu1);
while (menu1 != 1 && menu1 !=2){// Traitement des erreurs
printf("Erreur de saisie veuillez refaire votre choix ! \n");
printf("(1) Gestion Candidature\n");
printf("(2) Affichage Candidature\n");
printf("(3) Quitter\n");
scanf("%d", &menu1);
}
if (menu1 == 1){
printf("Menu : \n");//Menu gestion ajout/modification/suppression d'une candidature
printf("(1) Ajouter une Candidature\n (2) Modifier une Candidature\n (3) Supprimer une Candidature");
scanf("%d", &menugest1);
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
//}
//else if (menu1 == 2){
printf("");
}
}
//####################################### FILES #################################################