@ -32,21 +32,33 @@ int testVideChx (Filechx f){// fonction test si la Filechx est vide return 1 sin
Candidat lireCa ( FILE * fe ) // lit un candidat dans un fichier
Candidat lireCa ( FILE * fe ) // lit un candidat dans un fichier
{
{
Candidat c ; //candidat que l'on retournera
Candidat c ; //candidat que l'on retournera
Choix chx ; //pour la création de maillons
int cpt ; //pour la création de maillons
int cpt = 0 ; //qui servira à compter le nombre de choix
fscanf ( fe , " %*c%d " , & c . nEtu ) ;
fscanf ( fe , " %d " , c . nEtu ) ;
fscanf ( fe , " %s " , c . nom ) ;
fgets ( c . nom , 23 , fe ) ;
c . nom [ strlen ( c . nom ) - 1 ] = ' \0 ' ;
fscanf ( fe , " %s " , c . prenom ) ;
fgets ( c . prenom , 23 , fe ) ;
//fgets(c.prenom, 27, fe);
c . prenom [ strlen ( c . prenom ) - 1 ] = ' \0 ' ;
//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 ) ;
printf ( " %s \n " , c . prenom ) ;
c . lchx = init ( ) ; //initialisation de la liste
fscanf ( fe , " %f %f %f %f " , & c . moymat , & c . moyfr , & c . moyen , & c . moyspe ) ;
fscanf ( fe , " %d " , & c . nbchx ) ;
printf ( " %d " , c . nbchx ) ;
c . fchx = initchx ( ) ; //initialisation de la file
for ( cpt = 0 ; cpt < c . nbchx ; cpt + + )
{
//puts("je passe ici aussi\n");
Choix chx ;
chx = lireC ( fe ) ;
c . fchx = enf ( c . fchx , chx ) ;
}
return c ;
return c ;
}
}
/*
// FAIRE LECTURE CHOIX POUR METTRE EN PARAMETRE PLUTOT QUE LE FE
// FAIRE LECTURE CHOIX POUR METTRE EN PARAMETRE PLUTOT QUE LE FE
Filechx enfilechx ( Filechx f , File * fe ) { //fonction enfile un maillon choix en fin de file Choix
Filechx enfilechx ( Filechx f , F ILE * fe ) { //fonction enfile un maillon choix en fin de file Choix
Maillonchx * mch ;
Maillonchx * mch ;
int nbchoix , i , nbcand , numCand ;
int nbchoix , i , nbcand , numCand ;
char nom [ 30 ] , prenom [ 30 ] ;
char nom [ 30 ] , prenom [ 30 ] ;
@ -55,7 +67,7 @@ Filechx enfilechx ( Filechx f , File *fe){//fonction enfile un maillon choix en
mch = ( Maillonchx * ) malloc ( sizeof ( Maillonchx ) ) ;
mch = ( Maillonchx * ) malloc ( sizeof ( Maillonchx ) ) ;
if ( mch = = NULL ) {
if ( mch = = NULL ) {
printf ( " Probleme malloc " ) ;
printf ( " Probleme malloc " ) ;
return - 1 ;
exit ( - 1 ) ;
}
}
fscanf ( fe , " %d %d %s %s %f %f %f %f %f %d " , & nbcand , & numCand , nom , prenom , & nmat , & nfr , & nen , & nspe , & nDoss , & nbchoix ) ;
fscanf ( fe , " %d %d %s %s %f %f %f %f %f %d " , & nbcand , & numCand , nom , prenom , & nmat , & nfr , & nen , & nspe , & nDoss , & nbchoix ) ;
for ( i = 0 ; i < nbchoix ; i + + ) {
for ( i = 0 ; i < nbchoix ; i + + ) {
@ -71,7 +83,75 @@ Filechx enfilechx ( Filechx f , File *fe){//fonction enfile un maillon choix en
}
}
return f ;
return f ;
}
}
*/
//celle là c'est la bonne pour enfiler dans une file de choix
Filechx enf ( Filechx fchx , Choix c )
{
Maillonchx * m ;
m = ( Maillonchx * ) malloc ( sizeof ( Maillonchx ) ) ;
if ( m = = NULL ) { printf ( " err pb malloc maillon choix \n " ) ; exit ( - 1 ) ; }
strcpy ( m - > chx . ville , c . ville ) ;
strcpy ( m - > chx . dptmt , c . dptmt ) ;
m - > chx . dec = c . dec ;
m - > chx . valid = c . valid ;
m - > suivchx = NULL ;
if ( testVideChx ( fchx ) )
{
fchx . ttchx = m ;
fchx . kechx = m ;
}
else
{
fchx . kechx - > suivchx = m ;
fchx . kechx = m ;
}
return fchx ;
}
Filecand enfC ( Filecand fC , Candidat c )
{
Mailloncand * m ;
int cpt ;
m = ( Mailloncand * ) malloc ( sizeof ( Mailloncand ) ) ;
if ( m = = NULL ) { printf ( " pb malloc \n " ) ; exit ( - 1 ) ; }
m - > cand . nEtu = c . nEtu ;
strcpy ( m - > cand . nom , c . nom ) ;
strcpy ( m - > cand . prenom , c . prenom ) ;
m - > cand . moymat = c . moymat ;
m - > cand . moyfr = c . moyfr ;
m - > cand . moyen = c . moyen ;
m - > cand . moyspe = c . moyspe ;
m - > cand . noteDoss = c . noteDoss ;
m - > cand . nbchx = c . nbchx ;
m - > cand . fchx = initchx ( ) ;
for ( cpt = 0 ; cpt < c . nbchx ; cpt + + )
{
if ( c . fchx . ttchx = = NULL ) break ;
m - > cand . fchx = enf ( m - > cand . fchx , c . fchx . ttchx - > chx ) ;
c . fchx . ttchx = c . fchx . ttchx - > suivchx ;
}
m - > suivcand = NULL ;
if ( testVideCand ( fC ) )
{
fC . ttcand = m ;
fC . kecand = m ;
}
else
{
fC . kecand - > suivcand = m ;
fC . kecand = m ;
}
return fC ;
}
/*
// FAIRE LECTURE CANDIDAT POUR METTRE EN PARALLELE
// FAIRE LECTURE CANDIDAT POUR METTRE EN PARALLELE
Filecand enfilecand ( Filecand f , FILE * fe ) { // fonction enfile un maillon cand en fin de file Candidat
Filecand enfilecand ( Filecand f , FILE * fe ) { // fonction enfile un maillon cand en fin de file Candidat
@ -100,7 +180,7 @@ Filecand enfilecand (Filecand f, FILE *fe){// fonction enfile un maillon cand en
int chargement ( void ) { // chargement des files cand et chx
int chargement ( void ) { // chargement des files cand et chx
}
}
*/
@ -115,64 +195,8 @@ Choix lireC(FILE *fe)//fonction extraite de la partie 2
}
}
Listechx InsertTC ( Listechx list , Choix 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 ;
mchx - > suivchx = list ;
return mchx ;
}
Listechx InsertC ( Listechx list , Choix m ) //insert globalement dans liste de choix
{
if ( list = = NULL ) { return InsertTC ( list , m ) ; }
if ( strcmp ( list - > chx . dptmt , m . dptmt ) > 0 ) { return InsertTC ( list , m ) ; }
list - > suivchx = InsertC ( list - > suivchx , m ) ;
return list ;
}
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 ; }
c1 - > cand . nEtu = c . nEtu ;
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 . noteDoss = c . noteDoss ;
c1 - > cand . nbchx = c . nbchx ;
c1 - > cand . lchx = c . lchx ;
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 ;
}
Listecand InsertN ( Listecand list , Candidat c ) //insert globalement en fonction de la note
{
if ( list = = NULL ) { return InsertT ( list , c ) ; }
if ( list - > cand . noteDoss < = + c . noteDoss ) { return InsertT ( list , c ) ; }
list - > suivcand = InsertN ( list - > suivcand , c ) ;
return list ;
}
/*gardant ce modèle il nous faudra faire le chargement de files
Listecand Chargementlistecandidat ( FILE * fe , Listecand lC , int * nbC ) // fonction de chargement de la liste des candidats
Listecand Chargementlistecandidat ( FILE * fe , Listecand lC , int * nbC ) // fonction de chargement de la liste des candidats
{
{
int cpt , j ;
int cpt , j ;
@ -196,17 +220,25 @@ Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction d
}
}
return lC ;
return lC ;
}
}
*/
Filecand ChargementfileC ( Filecand fC , int * nbC ) //chargement du fichier dans cette liste de candidats avec le nombre nbC de candidats à lire dans le fichier
{
FILE * fe ;
int cpt ;
fe = fopen ( " part4.don " , " r " ) ;
if ( fe = = NULL ) { printf ( " pb ouv part4.don \n " ) ; exit ( - 1 ) ; }
printf ( " ollow \n " ) ;
fscanf ( fe , " %d " , nbC ) ;
for ( cpt = 0 ; cpt < * nbC ; cpt + + )
{
puts ( " here " ) ;
Candidat c ;
c = lireCa ( fe ) ;
fC = enfC ( fC , c ) ;
}
fclose ( fe ) ;
return fC ;
}
@ -216,9 +248,15 @@ void test (void){
fe = fopen ( " part4.don " , " r " ) ;
fe = fopen ( " part4.don " , " r " ) ;
if ( fe = = NULL ) {
if ( fe = = NULL ) {
printf ( " probleme d'ouverture de fichier " ) ;
printf ( " probleme d'ouverture de fichier " ) ;
return - 1 ;
return ;
}
}
Filecand fC ;
int nbC ;
printf ( " bon \n " ) ;
fC = initcand ( ) ;
printf ( " jour \n " ) ;
fC = ChargementfileC ( fC , & nbC ) ;
}
}