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

39 lines
1.4 KiB
C

#include "fileGestion.h"
/**
* @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
*
* @param nRow number of lign in the beginning of the file rawData.csv that has to be delete
*/
void clearRawData(int nRow){
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);
}
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);
}
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);
}
/**
* @brief use to write the file powerData.csv that contaign all power calculous results
*
* @param powerArray
* @param nCol size of the power array, correspond to the number of captor used
*/
void writePowerData(double powerArray[], int nCol){
FILE *f = fopen("powerData.csv","a+");
for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){
fprintf(f, "%f , ", powerArray[i]);
} else {
fprintf(f, "%f\n", powerArray[i]);
}
}
fclose(f);
}