From 8bd977ba6220aff94ef13a939853aa74267ad074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Gauthier?= Date: Tue, 21 Jun 2022 17:47:27 +0200 Subject: [PATCH] fix some warnings --- Code-C/getArray.c | 84 +++++++++++++++++++++++++------------------ Code-C/getArray.h | 4 +-- Code-C/main.c | 13 +++++-- Code-C/simulateFlux.c | 7 ++-- 4 files changed, 67 insertions(+), 41 deletions(-) diff --git a/Code-C/getArray.c b/Code-C/getArray.c index bdc7a79..a74282c 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -8,9 +8,9 @@ long **getlongArray(int N, int M) /* Allocate the array */ /* Check if allocation succeeded. (check for NULL pointer) */ int i; long **array; - array = (long **) malloc(N*sizeof(long *)); - for(i = 0 ; i < N ; i++) - array[i] = (long *) malloc( M*sizeof(long) ); + array = (long **)malloc(N * sizeof(long *)); + for (i = 0; i < N; i++) + array[i] = (long *)malloc(M * sizeof(long)); return array; } @@ -19,69 +19,82 @@ double **getDoubleArray(int N, int M) /* Allocate the array */ /* Check if allocation succeeded. (check for NULL pointer) */ int i; double **array; - array = (double **) malloc(N*sizeof(double *)); - for(i = 0 ; i < N ; i++) - array[i] = (double *) malloc( M*sizeof(double)); + array = (double **)malloc(N * sizeof(double *)); + for (i = 0; i < N; i++) + array[i] = (double *)malloc(M * sizeof(double)); return array; } -void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) { +void fillArrayWithRawData(char *rawDataFileName, long **p, int N, int M) +{ int i, j; char *buffer; size_t bufsize = 200; buffer = (char *)malloc(bufsize * sizeof(char)); - char* token; + int token; - FILE *f = fopen(rawDataFileName,"r"); + FILE *f = fopen(rawDataFileName, "r"); - for(i = 0 ; i < N ; i++){ - if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini + for (i = 0; i < N; i++) + { + if (!getline(&buffer, &bufsize, f)) + break; // condition d'arret de la boucle si fichier fini j = 0; - while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv - p[i][j] = atoi(token); + while ((token = strsep(&buffer, ",")) != 0) + { // séparation valeur par virgule initiale : csv + p[i][j] = token; j++; } } fclose(f); - } /** * @brief print all the element of a bidimensionnal array p of shape : N x M */ -void printArrayData(long** p, int N, int M) { - int i, j; - for(i = 0 ; i < N ; i++){ - printf("line n°%d : " , i); - for(int j = 0 ; j < M ; j++){ - printf("%ld , " , p[i][j]); - if(j==(M-1)) printf("\n"); +void printArrayData(long **p, int N, int M) +{ + for (int i = 0; i < N; i++) + { + printf("line n°%d : ", i); + for (int j = 0; j < M; j++) + { + printf("%ld , ", p[i][j]); + if (j == (M - 1)) + printf("\n"); } } } /** - * @brief verify if all the element of an array are not NULL, return - * + * @brief verify if all the element of an array are not NULL, return + * * @param p array to check * @param N number of rows in p * @param M number of columns in p * @return true if the array contaign no NULL element * @return false if at least one element is null */ -bool checkArrayFullyFill(long **p, int N){ - for(int i = 0 ; i < N ; i++){ - if(p[i][0] == '\0'){ return false; } +bool checkArrayFullyFill(long **p, int N) +{ + for (int i = 0; i < N; i++) + { + if (p[i][0] == '\0') + { + return false; + } } return true; } /** * @brief free memory allocate to an array p - * + * * @param p array to free memory * @param N number of rows in array */ -void freeArray(long **p, int N) { - for(int i = 0 ; i < N ; i++){ +void freeArray(long **p, int N) +{ + for (int i = 0; i < N; i++) + { free(p[i]); } free(p); @@ -89,19 +102,20 @@ void freeArray(long **p, int N) { /** * @brief Get the Raw Data Array object - * + * * @param rawDataFileName name of the file to use to file the array * @param N numbers of rows to have i the array * @param M numbers of columns to have i the array * @return long** the array fill with raw data */ -long **getRawDataArray(char* rawDataFileName){ +long **getRawDataArray(char *rawDataFileName) +{ long **p; p = getlongArray(nRowRawData, nCol); - fillArrayWithRawData(rawDataFileName,p ,nRowRawData, nCol); - //if(checkArrayFullyFill(p,nRow)){ - //clearRawData(N); - return p; + fillArrayWithRawData(rawDataFileName, p, nRowRawData, nCol); + // if(checkArrayFullyFill(p,nRow)){ + // clearRawData(N); + return p; /*} else{ return NULL; diff --git a/Code-C/getArray.h b/Code-C/getArray.h index a53bd0c..6cd847e 100644 --- a/Code-C/getArray.h +++ b/Code-C/getArray.h @@ -6,7 +6,7 @@ #include long **getRawDataArray(char *rawDataFileName); -void printArrayData(long** p, int N, int M); +void printArrayData(long **p, int N, int M); void freeArray(long **p, int N); -bool checkArrayFullyFill(long **p, int N ); +bool checkArrayFullyFill(long **p, int N); double **getDoubleArray(int N, int M); \ No newline at end of file diff --git a/Code-C/main.c b/Code-C/main.c index dd1fe9b..3bcb289 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -42,6 +42,7 @@ void *threadCalculPower(void *vargp) remove(fileName); } } + return NULL; } void *threadCalculAverage(void *vargp) @@ -58,6 +59,7 @@ void *threadCalculAverage(void *vargp) remove(fileName); } } + return NULL; } void *threadCalculBoth(void *vargp) @@ -75,6 +77,7 @@ void *threadCalculBoth(void *vargp) remove(fileName); } } + return NULL; } void *threadCalculGrowthRate(void *vargp) @@ -124,6 +127,7 @@ void *threadCalculGrowthRate(void *vargp) remove(fileName); } } + return NULL; } int main(int argc, char **argv) @@ -144,9 +148,14 @@ int main(int argc, char **argv) firstRawDataQueue = queueCreateEmpty(); // change this for create empty pthread_t rawData; - pthread_create(&rawData, NULL, threadSimulateFlux, (void *)&rawData); + if (pthread_create(&rawData, NULL, threadSimulateFlux, "threadSimulflux") != 0) + { + perror("pthread_create() error"); + exit(1); + } + pthread_t calcul; - pthread_create(&calcul, NULL, threadCalculGrowthRate, (void *)&calcul); + pthread_create(&calcul, NULL, threadCalculGrowthRate, "threadCalcul"); pthread_exit(NULL); } \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 460dd7b..fd31523 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -123,7 +123,6 @@ bool writeOneRawData(FILE *rawDataFile) char buff2[18]; int32_t values[8]; uint32_t valbin[8]; - quartet value; if (fread(&buff, 26, 1, stdin)) { @@ -146,11 +145,13 @@ bool writeOneRawData(FILE *rawDataFile) strncpy(&buff[8], buff2, 18); } } + int lastIndex = lastIndexCaptor(); for (int i = 1; i < 9; i++) { if (selectionCaptors[i - 1]) { + quartet value; value.octet1 = buff[3 * i + 1]; value.octet2 = buff[3 * i + 2]; value.octet3 = buff[3 * i + 3]; @@ -183,6 +184,7 @@ bool writeOneRawData(FILE *rawDataFile) return false; } } + return false; } void *threadSimulateFlux(void *vargp) @@ -202,8 +204,9 @@ void *threadSimulateFlux(void *vargp) queueAddLastQ(firstRawDataQueue, fileName, strlen(fileName)); // prepare next file now fileName = createNewRawDataFileName(); - FILE *rawDataFile = fopen(fileName, "w+"); + rawDataFile = fopen(fileName, "w+"); } } rawDataWriteFlag = false; + return NULL; }