60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
|
#include "getArray.h"
|
||
|
#include "initialParameters.h"
|
||
|
#include "fileGestion.h"
|
||
|
|
||
|
int **get(int N, int M) /* Allocate the array */
|
||
|
{
|
||
|
/* Check if allocation succeeded. (check for NULL pointer) */
|
||
|
int i;
|
||
|
int **array;
|
||
|
array = malloc(N*sizeof(int *));
|
||
|
for(i = 0 ; i < N ; i++)
|
||
|
array[i] = malloc( M*sizeof(int) );
|
||
|
return array;
|
||
|
}
|
||
|
|
||
|
void fill(int** p, int N, int M) {
|
||
|
int i, j;
|
||
|
char buffer[200];
|
||
|
char *token;
|
||
|
for(i = 0 ; i < N ; i++){
|
||
|
|
||
|
if (!fgets(buffer, sizeof buffer, stdin)) break; // condition d'arret de la boucle si fichier fini
|
||
|
//printf(buffer);
|
||
|
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv
|
||
|
p[i][0] = atoi(token);
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void print(int** p, int N, int M) {
|
||
|
int i, j;
|
||
|
for(i = 0 ; i < N ; i++)
|
||
|
for(j = 0 ; j < M ; j++)
|
||
|
printf("array[%d][%d] = %d\n", i, j, p[i][j]);
|
||
|
}
|
||
|
|
||
|
void freeArray(int** p, int N) {
|
||
|
int i;
|
||
|
for(i = 0 ; i < N ; i++)
|
||
|
free(p[i]);
|
||
|
free(p);
|
||
|
}
|
||
|
|
||
|
int main(int argc , char** argv){
|
||
|
int **p;
|
||
|
p = get(nRow, nCol);
|
||
|
fill(p ,nRow, nCol);
|
||
|
//print(p, nRow, nCol);
|
||
|
FILE *g = fopen(,"w"); //here to find the good one
|
||
|
replaceFile(nRow,g);
|
||
|
freeArray(p ,nRow);
|
||
|
return 0;
|
||
|
}
|