diff --git a/src/csv_reader_V2.c b/src/csv_reader_V2.c index 163ada8..7cbb71a 100644 --- a/src/csv_reader_V2.c +++ b/src/csv_reader_V2.c @@ -4,32 +4,65 @@ #include typedef struct Personne Personne; -struct Personne {int athId; int regId; int divId; char* lastName; char* firstName; char gender; int age; char* weight; char* height; int affiliateId; char* affiliateName; int overallScrore; int overallRank; int score18_1; char* scoreDisplay18_1; int rank18_1; int score18_2; char* scoreDisplay18_2; int rank18_2;int score18_2a; char* scoreDisplay18_2a; int rank18_2a;int score18_3; char* scoreDisplay18_3; int rank18_3;int score18_4; char* scoreDisplay18_4; int rank18_4;int score18_5; char* scoreDisplay18_5; int rank18_5; Personne* suivant}; +struct Personne { + int athId; + int regId; + int divId; + char* lastName; + char* firstName; + char gender; + int age; + char* weight; + char* height; + int affiliateId; + char* affiliateName; + int overallScrore; + int overallRank; + int score18_1; + char* scoreDisplay18_1; + int rank18_1; + int score18_2; + char* scoreDisplay18_2; + int rank18_2; + int score18_2a; + char* scoreDisplay18_2a; + int rank18_2a; + int score18_3; + char* scoreDisplay18_3; + int rank18_3; + int score18_4; + char* scoreDisplay18_4; + int rank18_4; + int score18_5; + char* scoreDisplay18_5; + int rank18_5; + Personne* suivant;}; + typedef Personne* Liste; -affiche_header_top50() +void affiche_header_top50() { printf("Index nom prenom score"); } -affiche_header_recherche() +void affiche_header_recherche() { printf("athId nom prenom gender age taille poids score18.1 score18.2 score 18.2a score18.3 score18.4 score18.5"); } -affiche_top50(Personne P, int i) +void affiche_top50(Personne P, int i) { - printf("%d %s %s %d", i , P.lastName, P.firstName, P.score); + printf("%d %s %s %d", i , P.lastName, P.firstName, P.overallScrore); } -affiche_recherche(Personne P) +void affiche_recherche(Personne P) { printf("%d %s %s %c %d %s %s %d %d %d %d %d %d", P.athId, P.lastName, P.firstName, P.gender, P.age, P.height, P.weight, P.score18_1, P.score18_2, P.score18_2a, P.score18_3, P.score18_4, P.score18_5); } // Conditionals -const bool IS_DEBUG = true; +const bool IS_DEBUG = false; // Constants const unsigned int BUFFER_SIZE = 2048; @@ -86,6 +119,15 @@ void read_csv_header(char * header_line) if (IS_DEBUG) display_header(); } + +void ajout_personne_tab(Personne P, char* token) +{ + + + +} + + void read_csv_file(const char * filename) { FILE* fp = fopen(filename, "r"); @@ -101,28 +143,49 @@ void read_csv_file(const char * filename) // 1st row is a header with field descriptions fgets(buffer, BUFFER_SIZE, fp); read_csv_header(buffer); + + Personne P[10]; + unsigned int i = 0; // Remaining rows are the entries while ( NULL != fgets(buffer, BUFFER_SIZE, fp) ) { - char* token; - unsigned int i = 0; - // strtok init. - token = strtok(buffer, CSV_DELIMITERS); - - while (NULL != token) - { - if (IS_DEBUG) printf("Field %d is %s\n", i++, token); - - // ... - // you can strcpy the `token` string in your data structures - // ... - - token = strtok(NULL, CSV_DELIMITERS); - } + P[i].athId = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].regId = atoi(strtok(NULL, CSV_DELIMITERS)); + P[i].divId = atoi(strtok(NULL, CSV_DELIMITERS)); + P[i].lastName = strtok(NULL, CSV_DELIMITERS); + P[i].firstName = strtok(buffer, CSV_DELIMITERS); + P[i].gender = *strtok(buffer, CSV_DELIMITERS); + P[i].age = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].weight = strtok(buffer, CSV_DELIMITERS); + P[i].height = strtok(buffer, CSV_DELIMITERS); + P[i].affiliateId = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].affiliateName = strtok(buffer, CSV_DELIMITERS); + P[i].overallScrore = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].overallRank = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].score18_1 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].scoreDisplay18_1 = strtok(buffer, CSV_DELIMITERS); + P[i].rank18_1 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].score18_2 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].score18_2a = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].scoreDisplay18_2a = strtok(buffer, CSV_DELIMITERS); + P[i].rank18_2a = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].score18_3 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].scoreDisplay18_3 = strtok(buffer, CSV_DELIMITERS); + P[i].rank18_3 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].score18_4 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].scoreDisplay18_4 = strtok(buffer, CSV_DELIMITERS); + P[i].rank18_4 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].score18_5 = atoi(strtok(buffer, CSV_DELIMITERS)); + P[i].scoreDisplay18_5 = strtok(buffer, CSV_DELIMITERS); + P[i].rank18_5 = atoi(strtok(buffer, CSV_DELIMITERS)); + + i++; } + printf("%d ", P[2].regId); + fclose(fp); } -- libgit2 0.21.2