Commit 813e29bb2efa631fe372ccf52804c362551d44bf

Authored by mdupre1
1 parent 690aa1f7

Lecture (non fini)

Showing 1 changed file with 85 additions and 22 deletions   Show diff stats
src/csv_reader_V2.c
@@ -4,32 +4,65 @@ @@ -4,32 +4,65 @@
4 #include <stdlib.h> 4 #include <stdlib.h>
5 5
6 typedef struct Personne Personne; 6 typedef struct Personne Personne;
7 -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}; 7 +struct Personne {
  8 + int athId;
  9 + int regId;
  10 + int divId;
  11 + char* lastName;
  12 + char* firstName;
  13 + char gender;
  14 + int age;
  15 + char* weight;
  16 + char* height;
  17 + int affiliateId;
  18 + char* affiliateName;
  19 + int overallScrore;
  20 + int overallRank;
  21 + int score18_1;
  22 + char* scoreDisplay18_1;
  23 + int rank18_1;
  24 + int score18_2;
  25 + char* scoreDisplay18_2;
  26 + int rank18_2;
  27 + int score18_2a;
  28 + char* scoreDisplay18_2a;
  29 + int rank18_2a;
  30 + int score18_3;
  31 + char* scoreDisplay18_3;
  32 + int rank18_3;
  33 + int score18_4;
  34 + char* scoreDisplay18_4;
  35 + int rank18_4;
  36 + int score18_5;
  37 + char* scoreDisplay18_5;
  38 + int rank18_5;
  39 + Personne* suivant;};
  40 +
8 typedef Personne* Liste; 41 typedef Personne* Liste;
9 42
10 43
11 -affiche_header_top50() 44 +void affiche_header_top50()
12 { 45 {
13 printf("Index nom prenom score"); 46 printf("Index nom prenom score");
14 } 47 }
15 48
16 -affiche_header_recherche() 49 +void affiche_header_recherche()
17 { 50 {
18 printf("athId nom prenom gender age taille poids score18.1 score18.2 score 18.2a score18.3 score18.4 score18.5"); 51 printf("athId nom prenom gender age taille poids score18.1 score18.2 score 18.2a score18.3 score18.4 score18.5");
19 } 52 }
20 53
21 -affiche_top50(Personne P, int i) 54 +void affiche_top50(Personne P, int i)
22 { 55 {
23 - printf("%d %s %s %d", i , P.lastName, P.firstName, P.score); 56 + printf("%d %s %s %d", i , P.lastName, P.firstName, P.overallScrore);
24 } 57 }
25 58
26 -affiche_recherche(Personne P) 59 +void affiche_recherche(Personne P)
27 { 60 {
28 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); 61 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);
29 } 62 }
30 63
31 // Conditionals 64 // Conditionals
32 -const bool IS_DEBUG = true; 65 +const bool IS_DEBUG = false;
33 66
34 // Constants 67 // Constants
35 const unsigned int BUFFER_SIZE = 2048; 68 const unsigned int BUFFER_SIZE = 2048;
@@ -86,6 +119,15 @@ void read_csv_header(char * header_line) @@ -86,6 +119,15 @@ void read_csv_header(char * header_line)
86 if (IS_DEBUG) display_header(); 119 if (IS_DEBUG) display_header();
87 } 120 }
88 121
  122 +
  123 +void ajout_personne_tab(Personne P, char* token)
  124 +{
  125 +
  126 +
  127 +
  128 +}
  129 +
  130 +
89 void read_csv_file(const char * filename) 131 void read_csv_file(const char * filename)
90 { 132 {
91 FILE* fp = fopen(filename, "r"); 133 FILE* fp = fopen(filename, "r");
@@ -101,28 +143,49 @@ void read_csv_file(const char * filename) @@ -101,28 +143,49 @@ void read_csv_file(const char * filename)
101 // 1st row is a header with field descriptions 143 // 1st row is a header with field descriptions
102 fgets(buffer, BUFFER_SIZE, fp); 144 fgets(buffer, BUFFER_SIZE, fp);
103 read_csv_header(buffer); 145 read_csv_header(buffer);
  146 +
  147 + Personne P[10];
  148 + unsigned int i = 0;
104 149
105 // Remaining rows are the entries 150 // Remaining rows are the entries
106 while ( NULL != fgets(buffer, BUFFER_SIZE, fp) ) 151 while ( NULL != fgets(buffer, BUFFER_SIZE, fp) )
107 { 152 {
108 - char* token;  
109 - unsigned int i = 0;  
110 -  
111 // strtok init. 153 // strtok init.
112 - token = strtok(buffer, CSV_DELIMITERS);  
113 -  
114 - while (NULL != token)  
115 - {  
116 - if (IS_DEBUG) printf("Field %d is %s\n", i++, token);  
117 -  
118 - // ...  
119 - // you can strcpy the `token` string in your data structures  
120 - // ...  
121 -  
122 - token = strtok(NULL, CSV_DELIMITERS);  
123 - } 154 + P[i].athId = atoi(strtok(buffer, CSV_DELIMITERS));
  155 + P[i].regId = atoi(strtok(NULL, CSV_DELIMITERS));
  156 + P[i].divId = atoi(strtok(NULL, CSV_DELIMITERS));
  157 + P[i].lastName = strtok(NULL, CSV_DELIMITERS);
  158 + P[i].firstName = strtok(buffer, CSV_DELIMITERS);
  159 + P[i].gender = *strtok(buffer, CSV_DELIMITERS);
  160 + P[i].age = atoi(strtok(buffer, CSV_DELIMITERS));
  161 + P[i].weight = strtok(buffer, CSV_DELIMITERS);
  162 + P[i].height = strtok(buffer, CSV_DELIMITERS);
  163 + P[i].affiliateId = atoi(strtok(buffer, CSV_DELIMITERS));
  164 + P[i].affiliateName = strtok(buffer, CSV_DELIMITERS);
  165 + P[i].overallScrore = atoi(strtok(buffer, CSV_DELIMITERS));
  166 + P[i].overallRank = atoi(strtok(buffer, CSV_DELIMITERS));
  167 + P[i].score18_1 = atoi(strtok(buffer, CSV_DELIMITERS));
  168 + P[i].scoreDisplay18_1 = strtok(buffer, CSV_DELIMITERS);
  169 + P[i].rank18_1 = atoi(strtok(buffer, CSV_DELIMITERS));
  170 + P[i].score18_2 = atoi(strtok(buffer, CSV_DELIMITERS));
  171 + P[i].score18_2a = atoi(strtok(buffer, CSV_DELIMITERS));
  172 + P[i].scoreDisplay18_2a = strtok(buffer, CSV_DELIMITERS);
  173 + P[i].rank18_2a = atoi(strtok(buffer, CSV_DELIMITERS));
  174 + P[i].score18_3 = atoi(strtok(buffer, CSV_DELIMITERS));
  175 + P[i].scoreDisplay18_3 = strtok(buffer, CSV_DELIMITERS);
  176 + P[i].rank18_3 = atoi(strtok(buffer, CSV_DELIMITERS));
  177 + P[i].score18_4 = atoi(strtok(buffer, CSV_DELIMITERS));
  178 + P[i].scoreDisplay18_4 = strtok(buffer, CSV_DELIMITERS);
  179 + P[i].rank18_4 = atoi(strtok(buffer, CSV_DELIMITERS));
  180 + P[i].score18_5 = atoi(strtok(buffer, CSV_DELIMITERS));
  181 + P[i].scoreDisplay18_5 = strtok(buffer, CSV_DELIMITERS);
  182 + P[i].rank18_5 = atoi(strtok(buffer, CSV_DELIMITERS));
  183 +
  184 + i++;
124 } 185 }
125 186
  187 + printf("%d ", P[2].regId);
  188 +
126 fclose(fp); 189 fclose(fp);
127 } 190 }
128 191