13/01 Partie 3 debug

master
Louis LABORIE 2 years ago
parent 832d2c8fb9
commit 1384a8fe84

306
SAEl.c

@ -1,158 +1,20 @@
#include "SAEl.h"
#include "SAE.h"
ListeDept creerListeDept(void)
int verifChefDepart(VilleIUT **tiut, int nbEle, char *dept, char *ville, char *nom)
{
return NULL;
}
VilleIUT **chargementVille(char *nomFich, int tphys, int *tailleL)
{
int i = 0, nbDept;
FILE *flot;
VilleIUT **tabV;
tabV = (VilleIUT **)malloc(sizeof(VilleIUT *) * tphys);
if (tabV == NULL)
{
printf("Erreur malloc tab!\n");
exit(1);
}
flot = fopen(nomFich, "r");
if (flot == NULL)
{
printf("Problème ouverture du fichier !\n");
exit(1);
}
*tailleL = 0;
tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT));
if (tabV[*tailleL] == NULL)
{
printf("Erreur malloc ville!\n");
fclose(flot);
exit(1);
}
*(tabV[*tailleL]) = lireVille(flot);
while (!feof(flot))
{
fscanf(flot, "%d", &nbDept);
printf("Nombre de dep : %d\n", nbDept);
tabV[*tailleL]->idDept = creerListeDept();
while (i < nbDept)
{
tabV[*tailleL]->idDept = traiterDept(tabV[*tailleL]->idDept, flot);
i += 1;
}
i = 0;
*tailleL += 1;
tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT));
if (tabV[*tailleL] == NULL)
{
printf("Erreur malloc ville!\n");
fclose(flot);
exit(1);
}
*(tabV[*tailleL]) = lireVille(flot);
}
if (tailleL == 0)
printf("Fichier vide !\n");
fclose(flot);
return tabV;
}
VilleIUT lireVille(FILE *flot)
{
VilleIUT v;
fgets(v.ville, 30, flot);
v.ville[strlen(v.ville) - 1] = '\0';
return v;
}
ListeDept traiterDept(ListeDept l, FILE *flot)
{
char nom[30], dept[30];
int nbPlaces;
fscanf(flot, "%s %d", dept, &nbPlaces);
fgets(nom, 30, flot);
nom[strlen(nom) - 1] = '\0';
printf("Nom du départ : %s\n", dept);
l = insererDept(l, dept, nom, nbPlaces);
return l;
}
ListeDept ajouterEnTeteDept(ListeDept l, char *dept, char *nom, int nbP)
int i, verif = 0;
ListeDept l;
for (i = 0; i < nbEle; i++)
{
MaillonDept *nouv;
nouv = (MaillonDept *)malloc(sizeof(MaillonDept));
if (nouv == NULL)
{
printf("Erreur malloc !\n");
exit(1);
}
strcpy(nouv->departement, dept);
nouv->nbPlaces = nbP;
strcpy(nouv->nom, nom);
nouv->suiv = l;
return nouv;
}
void affichageListeDept(ListeDept l) // itératif
if (strcmp(tiut[i]->ville, ville) == 0)
{
l = tiut[i]->idDept;
while (l != NULL)
{
printf("- %s :\t|%d places\t\t%s|\n", l->departement, l->nbPlaces, l->nom);
l = l->suiv;
}
}
ListeDept insererDept(ListeDept l, char *dept, char *nom, int nbP)
{ // récursif
if (l == NULL)
return ajouterEnTeteDept(l, dept, nom, nbP);
if ((strcmp(dept, l->departement)) < 0)
return ajouterEnTeteDept(l, dept, nom, nbP);
if ((strcmp(dept, l->departement)) == 0)
return l;
l->suiv = insererDept(l->suiv, dept, nom, nbP);
return l;
}
ListeDept supprimerEnTêteDept(ListeDept l)
if (strcmp(l->departement, dept) == 0)
{
MaillonDept *aux;
if (l == NULL)
if (strcmp(l->responsable, nom) == 0)
{
printf("suppression interdite\n");
exit(1);
}
if (l->suiv == NULL)
return NULL;
aux = l;
l = l->suiv;
free(aux);
return l;
}
ListeDept supprimerDept(ListeDept l, char *code)
{
if (l == NULL)
return l;
if ((strcmp(code, l->departement)) < 0)
return l;
if ((strcmp(code, l->departement)) == 0)
return supprimerEnTêteDept(l);
l->suiv = supprimerDept(l->suiv, code);
return l;
}
int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* nom) {
int i, verif = 0;
ListeDept l;
for (i = 0 ; i < nbEle ; i++) {
if (strcmp(tiut[i]->ville,ville) == 0) {
l = tiut[i]->idDept;
while (l != NULL) {
if (strcmp(l->departement,dept) == 0) {
if (strcmp(l->responsable,nom) == 0) {
verif = 1;
}
}
@ -163,7 +25,8 @@ int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* n
return verif;
}
int menuResponsableAffiche(void) {
int menuResponsableAffiche(void)
{
int choix;
printf("####################################################\n");
printf("\t\t|Menu Responsable|\n\n");
@ -177,11 +40,13 @@ int menuResponsableAffiche(void) {
return choix;
}
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL) {
int choix, codeRet;
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat **tcandid, int tailleL)
{
int choix, codeRet, nb;
char dept[30];
char ville[30];
char nom[30];
Candidat** tabCandidV;
printf("Nom du département concernée : ");
scanf("%s", dept);
printf("\nNom de la ville concernée : ");
@ -192,15 +57,17 @@ int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int taill
nom[strlen(nom) - 1] = '\0';
printf("\n");
codeRet = verifChefDepart(tiut, nbEle, dept, ville, nom);
if (codeRet == 0) return 0;
if (codeRet == 0)
return 0;
while (1)
{
choix = menuResponsableAffiche();
system("clear");
switch(choix) {
switch (choix)
{
case 1:
candidDept(tcandid,dept,ville,tailleL);
examinerCandid(tcandid,tailleL);
tabCandidV = candidDept(tcandid, dept, ville, tailleL,&nb);
examinerCandid(tabCandidV, nb, dept, ville);
system("clear");
break;
case 9:
@ -208,40 +75,9 @@ int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int taill
case 10:
return -1;
}
}
}
/*
void affichageListeDeptR(ListeDept l)
{
if (l->suiv == NULL)
printf("%d\n", l->v);
printf("%d =>", l->v);
affichageListeDeptR(l->suiv);
}
int tete(ListeDept l)
{
if (l == NULL)
{
printf("opération interdite\n");
exit(1);
}
return l->v;
}
*/
bool vide(ListeDept l)
{
if (l == NULL)
return true; // 1
return false; // 0
}
/*
int longueur(ListeDept l)
{
@ -255,56 +91,56 @@ int longueur(ListeDept l)
}
*/
ListeDept rechercheDept(ListeDept l, char code[])
{
if (l == NULL)
return NULL;
if ((strcmp(code, l->departement)) < 0)
return NULL;
if (strcmp(code, l->departement) == 0)
return l;
return rechercheDept(l->suiv, code);
}
// ListeDept rechercheDept(ListeDept l, char code[])
// {
// if (l == NULL)
// return NULL;
// if ((strcmp(code, l->departement)) < 0)
// return NULL;
// if (strcmp(code, l->departement) == 0)
// return l;
// return rechercheDept(l->suiv, code);
// }
void SauvegarderIUT(VilleIUT **tabV, int tailleL)
{
int i, nbDept;
FILE *flot;
flot = fopen("res.txt", "w");
for (i = 0; i < tailleL; i++)
{
fprintf(flot, "%s\n", tabV[i]->ville);
nbDept = longueurListe(tabV[i]->idDept);
fprintf(flot, "%d\n", nbDept);
SauvegarderListe(tabV[i]->idDept, flot);
free(tabV[i]);
}
}
// void SauvegarderIUT(VilleIUT **tabV, int tailleL)
// {
// int i, nbDept;
// FILE *flot;
// flot = fopen("res.txt", "w");
// for (i = 0; i < tailleL; i++)
// {
// fprintf(flot, "%s\n", tabV[i]->ville);
// nbDept = longueurListe(tabV[i]->idDept);
// fprintf(flot, "%d\n", nbDept);
// SauvegarderListe(tabV[i]->idDept, flot);
// free(tabV[i]);
// }
// }
void SauvegarderListe(ListeDept l, FILE *flot)
{
MaillonDept *tmp;
while (l->suiv != NULL)
{
tmp = l;
fprintf(flot, "%s %d %s\n", l->departement, l->nbPlaces, l->nom);
l = l->suiv;
free(tmp);
}
fprintf(flot, "%s %d %s\n", l->departement, l->nbPlaces, l->nom);
free(l);
}
// void SauvegarderListe(ListeDept l, FILE *flot)
// {
// MaillonDept *tmp;
// while (l->suiv != NULL)
// {
// tmp = l;
// fprintf(flot, "%s %d %s\n", l->departement, l->nbPlaces, l->nom);
// l = l->suiv;
// free(tmp);
// }
// fprintf(flot, "%s %d %s\n", l->departement, l->nbPlaces, l->nom);
// free(l);
// }
int longueurListe(ListeDept l)
{
int cpt = 0;
while (l != NULL)
{
cpt += 1;
l = l->suiv;
}
return cpt;
}
// int longueurListe(ListeDept l)
// {
// int cpt = 0;
// while (l != NULL)
// {
// cpt += 1;
// l = l->suiv;
// }
// return cpt;
// }
int traiterCandidIUTDept(Candidat *candid, char *dept, char *ville)
{
@ -333,7 +169,8 @@ int traiterCandidIUTDept(Candidat *candid, char *dept, char *ville)
Candidat** candidDept(Candidat** tabCandidat, char* dept, char* ville, int tailleL, int* nb)
{
int tphys = 50, i, codeRetour;
Candidat **tabCandDept = (Candidat **)malloc(sizeof(Candidat *) * tphys);
Candidat **tabCandDept;
tabCandDept = (Candidat **)malloc(sizeof(Candidat *) * tphys);
if (tabCandDept == NULL)
{
printf("Pb malloc tab candid\n");
@ -345,7 +182,7 @@ Candidat **candidDept(Candidat **tabCandidat, char *dept, char *ville, int taill
codeRetour = traiterCandidIUTDept(tabCandidat[i], dept, ville);
if (codeRetour == 1)
{
tabCandDept[i] = tabCandidat[i];
tabCandDept[*nb] = tabCandidat[i];
*nb += 1;
}
}
@ -356,6 +193,7 @@ void SauvegardeCandidAdmis(Candidat **tab, int nb, int admis)
{
FILE *flot;
int i;
float moy;
if (admis == 1)
flot = fopen("candidAdmis.txt", "w");
else
@ -373,7 +211,7 @@ void SauvegardeCandidAdmis(Candidat **tab, int nb, int admis)
fclose(flot);
}
void examinerCandid(Candidat **tabCandid, int nb)
void examinerCandid(Candidat **tabCandid, int nb, char* dept, char* ville)
{
int nbAdmis, i, comptAdmis = 0, j, comptAttente = 0;
float mini, moy;

@ -2,50 +2,22 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "SAE.h"
typedef struct maillondept {
char departement[30];
int nbPlaces;
char nom[30];
struct maillondept* suiv;
}MaillonDept;
typedef MaillonDept* ListeDept;
typedef struct {
char ville[30];
ListeDept idDept;
}VilleIUT;
ListeDept creerListeDept(void);
ListeDept ajouterEnTeteDept(ListeDept l, char* dept, char* nom, int nbP);
ListeDept insererDept(ListeDept l, char *dept, char *nom, int nbP);
void affichageListeDept(ListeDept l);
VilleIUT lireVille(FILE *flot);
ListeDept traiterDept(ListeDept l, FILE *flot);
VilleIUT** chargementVille(char* nomFich, int tphys, int* tailleL);
ListeDept supprimerDept(ListeDept l, char *code);
int longueurListe(ListeDept l);
// PARTIE 3
void SauvegarderIUT(VilleIUT** tabV, int tailleL);
int traiterCandidIUTDept(Candidat* candid,char* dept, char* ville);
void SauvegarderListe(ListeDept l, FILE* flot);
Candidat** candidDept(Candidat** tabCandidat, char* dept, char* ville, int tailleL, int* nb);
bool verifSelection(void);
void SauvegardeCandidAdmis(Candidat** tab, int nb, int admis);
void creationDept(VilleIUT **tiut, int nbEle);
void examinerCandid(Candidat **tabCandid, int nb, char* dept, char* ville);
int rechVille(VilleIUT **tiut, int nbEle, char code[], int *trouve);
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL);
int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* nom);
@ -53,42 +25,3 @@ int menuResponsableAffiche(void);
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL);
// PARTIE 3
typedef struct
{
char departement[30];
int decisionDept;
int decisionCandid;
}ChoixDept;
typedef struct maillonEtu
{
char iutCandid[30];
int nbChoix;
ChoixDept **tabDept;
struct maillonEtu *suiv;
}MaillonCandid, *ListeCandid;
typedef struct
{
int id;
char nom[30];
char prenom[30];
float note[4];
MaillonCandid *idCandIUT;
}Candidat;
int traiterCandidIUTDept(Candidat* candid,char* dept, char* ville);
Candidat** candidDept(Candidat** tabCandidat, char* dept, char* ville, int tailleL);
void SauvegardeCandidAdmis(Candidat** tab, int nb, int admis);
void examinerCandid(Candidat **tabCandid, int nb);
int gestionResponsable(VilleIUT **tiut, int nbEle);

@ -0,0 +1,2 @@
Paul Bocluse 12.0
Don Qui Roté 10.0

@ -0,0 +1,2 @@
Michel Cool 13.2
Matteo Skater 13.0

@ -1,4 +1,4 @@
4
6
1
Paul Bocluse
14 9 7 18
@ -51,3 +51,27 @@ Informatique
Réseaux
0
0
5
Michel Cool
14 9 12 18
1
Clermont-Ferrand
2
Informatique
0
0
Réseaux
0
0
6
Matteo Skater
10 14 15 13
1
Clermont-Ferrand
2
Informatique
0
0
Réseaux
0
0

Loading…
Cancel
Save