Ajout d'une fonction qui récupère le nom de toutes les équipe d'une liste

This commit is contained in:
Yohan Boujon 2022-11-28 23:24:50 +01:00
parent 2fb5d11074
commit f39ebcf364
4 changed files with 60 additions and 11 deletions

View file

@ -4,7 +4,7 @@
#include "coureur.h" //inclure le fichier "coureur.h" qui contien les libs et la structure coureur
#define TEMPSMAX 300
#define TEMPSMIN 80
#define TEMPSDOP 78
#define TEMPSDOP 79
struct element{ //definition de la structure qui element qui sera encaspule/chaine
coureur * coureurActuel; //"contient" l'adresse d'une structure coureur
@ -33,5 +33,8 @@ int tailleListe(liste l); //retourne le no
coureur * getCoureur(liste l,int nb); //retourne le courreur contenue dans l'element nb d'une liste (on considere un element 0)
void invertCoureur(liste * l,int nb); //inverse l'element nb et nb+1 dans une liste (on considere un element 0)
void triListe(liste * l,int taille); //trie bulle des element d'une liste a partir du temps contenue dans la structure encapsule dans l'element
char ** initMatrix(int sizeCol,int sizeLine);
bool isStringInMatrix(char ** matrix, char * string, int size);
void readTeams(char ** matrix, int sizeCol, int sizeLine, liste l);
int test(void);
#endif

View file

@ -5,10 +5,11 @@
#include <string.h>
#include <stdbool.h>
#include "liste.h"
#define MAXLINE 50
int getNbLines(void);
int getFileSize(FILE * readFile);
liste getStringFromFile(int nbLines,int * size, int * stepsNb,int * teamsNb);
liste getListFromFile(int nbLines,int * size, int * stepsNb,int * teamsNb);
char * getLine(char * string,int line);
liste string2Liste(char * string,int nbLines);
void string2Coureur(char * string,char * nom, char * prenom, int * dossard);

View file

@ -6,7 +6,7 @@ int main(void)
int size, stepsNb, teamsNb, listeTaille, dopageCount=0;
srand(time(NULL));
int fileLines = getNbLines();
liste l = getStringFromFile(fileLines,&size,&stepsNb,&teamsNb);
liste l = getListFromFile(fileLines,&size,&stepsNb,&teamsNb);
liste dopageList = initListe();
listeTaille = tailleListe(l);
@ -27,13 +27,13 @@ int main(void)
allerDebut(&l);
}
allerDebut(&l);
printf(" --- AVANT : ---\n");
printlist(l);
char ** tabTeam = initMatrix(teamsNb,MAXLINE);
readTeams(tabTeam,teamsNb,MAXLINE,l);
dopageCount=effacerListe(&l,&dopageList);
printf("\n --- APRES : ---\n");
//printf("\n --- CLASSEMENT GENERAL : ---\n");
triListe(&l,tailleListe(l));
printlist(l);
printf("\n --- NOMBRE DE PERSONNES DOPEES : %d ---\n",dopageCount);
//printlist(l);
//printf("\n --- NOMBRE DE PERSONNES DOPEES : %d ---\n",dopageCount);
return 0;
}
@ -344,9 +344,55 @@ void triListe(liste * l,int taille)
}
}
/**
* @brief Initialise un tableau de chaîne de caractères
*
* @param sizeCol taille des colonnes
* @param sizeLine taille de chaque ligne
* @return int** Une matrice de caractère
*/
char ** initMatrix(int sizeCol,int sizeLine)
{
char ** matrix;
matrix = (char **)(malloc(sizeLine*sizeof(char *)));
for(int i=0;i<sizeLine;i++)
{
*(matrix+i) = (char *)(malloc(sizeCol*sizeof(char)));
}
return matrix;
}
bool isStringInMatrix(char ** matrix, char * string, int size)
{
for(int i=0;i<size;i++)
{
if(strcmp(matrix[i],string) == 0)
{
return true;
}
}
return false;
}
void readTeams(char ** matrix, int sizeCol, int sizeLine, liste l)
{
int i=0;
struct element * elementCourant = l.courant;
struct element * elementFin = l.fin;
while(elementCourant->suiv != elementFin->suiv)
{
if(!isStringInMatrix(matrix,elementCourant->coureurActuel->equipe,sizeCol))
{
matrix[i]=elementCourant->coureurActuel->equipe;
i++;
}
elementCourant=elementCourant->suiv;
}
}
int test(void)
{
coureur * c1 = creerCoureur("Paris","Simon",15,"TRAUFORE",50000);
coureur * c1 = creerCoureur("Paris","Simon",15,"TRAUFORE",50000);
coureur * c2 = creerCoureur("Bougeont","Yoann",65,"MEILLEUR",99994);
coureur * c3 = creerCoureur("Barakai","Obama",120,"AMERICA",372);
coureur * c4 = creerCoureur("Boujon","Yohan",56,"MAISYEUR",49999);

View file

@ -1,5 +1,4 @@
#include "../header/readfile.h"
#define MAXLINE 50
/**
* @brief Récupère le nombre de ligne d'un fichier
@ -36,7 +35,7 @@ int getNbLines(void)
* @param teamsNb int * renvoi le nombre d'équipes
* @return liste de coureurs
*/
liste getStringFromFile(int nbLines,int * size, int * stepsNb,int * teamsNb)
liste getListFromFile(int nbLines,int * size, int * stepsNb,int * teamsNb)
{
liste l = initListe();
FILE * readFile=fopen("fichier_coureurs.txt","r");