2022-06-01 12:32:04 +02:00
|
|
|
#include "getArray.h"
|
|
|
|
#include "fileGestion.h"
|
2022-06-03 17:02:49 +02:00
|
|
|
//#include <string.h>
|
2022-06-01 12:32:04 +02:00
|
|
|
|
2022-06-03 17:02:49 +02:00
|
|
|
long **get(int N, int M) /* Allocate the array */
|
2022-06-01 12:32:04 +02:00
|
|
|
{
|
|
|
|
/* Check if allocation succeeded. (check for NULL pointer) */
|
|
|
|
int i;
|
2022-06-03 17:02:49 +02:00
|
|
|
long **array;
|
|
|
|
array = (long **) malloc(N*sizeof(long *));
|
2022-06-01 12:32:04 +02:00
|
|
|
for(i = 0 ; i < N ; i++)
|
2022-06-03 17:02:49 +02:00
|
|
|
array[i] = (long *) malloc( M*sizeof(long) );
|
2022-06-01 12:32:04 +02:00
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2022-06-03 17:02:49 +02:00
|
|
|
void fillRawData(long** p, int N, int M) {
|
2022-06-01 12:32:04 +02:00
|
|
|
int i, j;
|
|
|
|
|
2022-06-03 17:02:49 +02:00
|
|
|
char *buffer;
|
|
|
|
size_t bufsize = 200;
|
|
|
|
buffer = (char *)malloc(bufsize * sizeof(char));
|
|
|
|
char* token;
|
2022-06-01 12:32:04 +02:00
|
|
|
|
2022-06-03 17:02:49 +02:00
|
|
|
FILE *f = fopen("rawData.csv","r");
|
|
|
|
for(i = 0 ; i < N ; i++){
|
|
|
|
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini
|
|
|
|
printf("%s",buffer);
|
|
|
|
j = 0;
|
|
|
|
while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv
|
|
|
|
//printf("%s ," , token);
|
|
|
|
p[i][j] = atoi(token);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
/*
|
2022-06-01 12:32:04 +02:00
|
|
|
for(j = 1 ; j < M ; j++){
|
|
|
|
|
|
|
|
token = strtok(NULL, ","); // séparation valeur par virgule : csv
|
|
|
|
if(token == NULL) break; // condition d'arrêt de la séparartion
|
|
|
|
p[i][j] = atoi(token); //transtypage char to int
|
|
|
|
//printf(token);
|
|
|
|
}
|
2022-06-03 17:02:49 +02:00
|
|
|
*/
|
2022-06-01 12:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 17:02:49 +02:00
|
|
|
void printArrayData(long** p, int N, int M) {
|
2022-06-01 12:32:04 +02:00
|
|
|
int i, j;
|
2022-06-03 17:02:49 +02:00
|
|
|
for(i = 0 ; i < N ; i++){
|
|
|
|
printf("line n°%d : %d , %d , %d , %d , %d , %d , %d , %d \n" ,i,p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7]);
|
|
|
|
}
|
2022-06-01 12:32:04 +02:00
|
|
|
}
|
|
|
|
|
2022-06-03 17:02:49 +02:00
|
|
|
void freeArray(long **p, int N) {
|
2022-06-01 12:32:04 +02:00
|
|
|
int i;
|
|
|
|
for(i = 0 ; i < N ; i++)
|
|
|
|
free(p[i]);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
2022-06-03 17:02:49 +02:00
|
|
|
long **getRawDataArray(int N , int M){
|
|
|
|
long **p;
|
2022-06-01 18:02:32 +02:00
|
|
|
p = get(N, M);
|
|
|
|
fillRawData(p ,N, M);
|
|
|
|
return p;
|
2022-06-03 17:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void main(int argc , char argv[]){
|
|
|
|
long **p;
|
|
|
|
p = getRawDataArray(10,9);
|
|
|
|
printArrayData(p,10,9);
|
2022-06-01 12:32:04 +02:00
|
|
|
}
|