Traitement-signal-plantes/Code-C/fileGestion.c

49 lines
1.5 KiB
C
Raw Normal View History

2023-06-01 17:22:38 +02:00
#include "./Include/fileGestion.h"
2022-06-01 12:32:04 +02:00
2022-06-09 17:34:24 +02:00
/**
* @brief function that delete nRow lign in the beginning of the file rawData.csv . This function is necessary to not deal with the same ligns over and over
*
2022-06-09 17:34:24 +02:00
* @param nRow number of lign in the beginning of the file rawData.csv that has to be delete
*/
void clearRawData(int nRow)
{
2022-06-01 12:32:04 +02:00
char buffer[256];
FILE *f = fopen("newFile.csv", "w+");
FILE *g = fopen("rawData.csv", "r");
for (int i = 0; i < nRow; i++)
{ // first the program read the first nRow ligns of the csv file but do nothing
fgets(buffer, sizeof buffer, g);
2022-06-01 12:32:04 +02:00
}
while (1)
{ // then, till the end of the csv file it copy the lign to a new csv : newFile.csv
if (!fgets(buffer, sizeof buffer, g))
break;
fprintf(f, "%s", buffer);
2022-06-01 12:32:04 +02:00
}
remove("rawData.csv");
rename("newFile.csv", "rawData.csv"); // finally we remove the original file and rename the new one to replace rawData.csv
fclose(f);
fclose(g);
2022-06-01 12:32:04 +02:00
}
2022-06-09 17:34:24 +02:00
/**
2022-06-14 10:46:12 +02:00
* @brief use to write one lign in the file "fileName"
*
2022-06-14 10:46:12 +02:00
* @param array array that contaign all the values to write in the file
* @param nCol size of the array (correspond to the number of captor used)
2022-06-09 17:34:24 +02:00
*/
void appendDataInFile(char *fileName, double array[], int nCol)
{
FILE *f = fopen(fileName, "a+");
for (int i = 0; i < nCol; i++)
{
if (i < nCol - 1)
{
2022-06-14 10:46:12 +02:00
fprintf(f, "%f , ", array[i]);
}
else
{
2022-06-14 10:46:12 +02:00
fprintf(f, "%f\n", array[i]);
2022-06-02 14:29:21 +02:00
}
}
2022-06-08 11:25:19 +02:00
fclose(f);
2022-06-14 18:01:52 +02:00
}