Traitement-signal-plantes/C-Script/getArray.c

46 lines
1.2 KiB
C
Raw Normal View History

2022-05-30 18:01:28 +02:00
#include "main.h"
2022-05-05 16:40:03 +02:00
2022-05-30 18:01:28 +02:00
int getArray(){
2022-05-30 15:14:22 +02:00
2022-05-30 18:01:28 +02:00
int nCol = 9; // imposé par le nombre de sortie du capteur Vegetal Signal
2022-05-30 15:14:22 +02:00
int tab[nRow][nCol]; // création de la matrice contenant les valeurs , nRow définit dans les paramètre de la fonction
2022-05-05 16:40:03 +02:00
2022-05-30 15:14:22 +02:00
char buffer[200]; //200 valeur arbitraire
2022-05-05 16:40:03 +02:00
char *token;
2022-05-30 15:14:22 +02:00
for(int i = 0 ; i < nRow ; i++){
2022-05-30 12:54:56 +02:00
2022-05-30 15:14:22 +02:00
if (!fgets(buffer, sizeof buffer, stdin)) break; // condition d'arret de la boucle si fichier fini
2022-05-30 18:01:28 +02:00
//printf(buffer);
2022-05-30 15:14:22 +02:00
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv
2022-05-30 18:01:28 +02:00
tab[i][0] = atoi(token);
2022-05-30 12:54:56 +02:00
2022-05-30 18:01:28 +02:00
for(int j = 1 ; j < nCol ; j++){
2022-05-30 15:14:22 +02:00
token = strtok(NULL, ",");
if(token == NULL) break;
tab[i][j] = atoi(token); //transtypage char to int
2022-05-30 18:01:28 +02:00
fprintf(stdout,token);
2022-05-05 16:40:03 +02:00
}
}
2022-05-30 12:54:56 +02:00
}
2022-05-30 18:01:28 +02:00
void newFile(){
char buffer[256];
for(int i = 0; i < nRow; i++){
fgets(buffer , sizeof buffer , stdin);
printf("Line : %s\n" , buffer);
}
while(1){
if(!fgets(buffer,sizeof buffer , stdin)) break;
fprintf(stdin,"%s\n",buffer);
}
for(int i = 0; i < nRow; i++){
fprintf(stdin,"\n");
}
}
2022-05-30 12:54:56 +02:00
int main(int argc , char** argv){
2022-05-30 18:01:28 +02:00
getArray();
newFile();
2022-05-30 12:54:56 +02:00
}