From d6eecf0cee75dfb53007c9d04ec7efb9aeefb711 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 9 Feb 2026 03:43:16 +0100 Subject: [PATCH] eg --- AcquiringLand/Fundamentals/bad_practice.c | 10 +++- AcquiringLand/Fundamentals/insert_string.c | 30 ++++++----- AcquiringLand/Fundamentals/itoa.c | 7 +-- AcquiringLand/Fundamentals/join_strings.c | 57 +++++++++++++++++++++ AcquiringLand/Fundamentals/leaks.c | 9 +++- AcquiringLand/Fundamentals/magic_arrays.c | 49 ++++++++++++++++++ AcquiringLand/Fundamentals/test | Bin 19344 -> 0 bytes AcquiringLand/Fundamentals/trespass.c | 1 + 8 files changed, 143 insertions(+), 20 deletions(-) delete mode 100755 AcquiringLand/Fundamentals/test diff --git a/AcquiringLand/Fundamentals/bad_practice.c b/AcquiringLand/Fundamentals/bad_practice.c index 341a5ec..e1cb87a 100644 --- a/AcquiringLand/Fundamentals/bad_practice.c +++ b/AcquiringLand/Fundamentals/bad_practice.c @@ -3,7 +3,15 @@ int *division(int input, int by) { - int value = input / by; + + //int value = input / by; + if (by != 0){ + //int value = input / by; + } + else + return + + //int value = 0; int *ptr = &value; return ptr; } diff --git a/AcquiringLand/Fundamentals/insert_string.c b/AcquiringLand/Fundamentals/insert_string.c index 0bb36ab..1466620 100644 --- a/AcquiringLand/Fundamentals/insert_string.c +++ b/AcquiringLand/Fundamentals/insert_string.c @@ -5,21 +5,20 @@ char **insert_string(char **strings_array, int *array_size, char *insert_str, in char **rslt = malloc((*array_size + 1 )* sizeof(char *)); + if(rslt == NULL) return NULL; int index_clc = 0; + int index_clc2 = 0; //char *temp; - while (index_clc < *array_size){ + while (index_clc < *array_size + 1){ - if (index_clc == index){ - *(rslt + index_clc) = insert_str; - index_clc ++; - } + if (index_clc == index) *(rslt + index_clc) = insert_str; else{ - *(rslt + index_clc) = *(strings_array + index_clc); - } - + *(rslt + index_clc) = *(strings_array + index_clc2); + index_clc2 ++; + } /* if (index_clc >= index){ @@ -33,20 +32,23 @@ char **insert_string(char **strings_array, int *array_size, char *insert_str, in //*(strings_array + index) = insert_str; //free(temp); + *array_size = *array_size + 1; return rslt; } - +/* int main(){ char *tests[] = {"This", "is", "a", "long", "example"}; char *ins = "very"; int ted = 5; char **rslt = insert_string(tests, &ted, ins ,3); - int index = 0; - while (index < 6){ - printf("%s", *(rslt + index)); - index ++; + + if(rslt != NULL){ + + for (int i = 0; i < ted; i ++) printf("%s",rslt[i]); } + printf("\n"); + free (rslt); } - +*/ diff --git a/AcquiringLand/Fundamentals/itoa.c b/AcquiringLand/Fundamentals/itoa.c index 766a9a7..1239bec 100644 --- a/AcquiringLand/Fundamentals/itoa.c +++ b/AcquiringLand/Fundamentals/itoa.c @@ -23,7 +23,8 @@ char *my_itoa(int value){ int taille = get_number_length(value); char *rslt = malloc(taille + 1 * sizeof(char)); - + if (rslt == NULL) return NULL; + if (value < 0){ value = value * -1; *rslt = '-'; @@ -46,7 +47,7 @@ char *my_itoa(int value){ return rslt; } - +/* int main(){ printf("TESTS 1 \n"); printf("%i\n", get_number_length(7)); //1 @@ -66,4 +67,4 @@ int main(){ printf("%s\n", rslt); free(rslt); -} +}*/ diff --git a/AcquiringLand/Fundamentals/join_strings.c b/AcquiringLand/Fundamentals/join_strings.c index e69de29..77efdf9 100644 --- a/AcquiringLand/Fundamentals/join_strings.c +++ b/AcquiringLand/Fundamentals/join_strings.c @@ -0,0 +1,57 @@ +#include +#include +#include +char *join_strings(char *strings[], int count){ + + if (strings == NULL) return NULL; + + int tot = 0; + int index = 0; + //connaitre taille des str dans strings + for (int i = 0; i < count; i++){ + + index = 0; + //binf + while (strings[i][index]){ + tot ++; + index ++; + //printf("boucle inf ici"); + } + + } + + char *rslt = malloc((tot + count) * sizeof(char)); + if (rslt == NULL) return NULL; + + tot = 0; + + for (int i = 0; i < count; i ++){ + index = 0; + //binf + while (strings[i][index]){ + + *(rslt + tot) = strings[i][index]; + index ++; + tot ++; + } + if (i == count - 1) + *(rslt + tot) = '\0'; + else *(rslt + tot) = ' '; + tot ++; + } + //free(strings); + return rslt; +} +/* +int main(){ + + char *str[] = {"Hello", "from ", "Java", "swimming pool"}; + char *test = join_strings(str, 4); + printf("%s\n", test); + free (test); + + test = join_strings(NULL, 0); + printf("%s\n", test); + free(test); + +}*/ diff --git a/AcquiringLand/Fundamentals/leaks.c b/AcquiringLand/Fundamentals/leaks.c index fd08f34..78ae9c8 100644 --- a/AcquiringLand/Fundamentals/leaks.c +++ b/AcquiringLand/Fundamentals/leaks.c @@ -3,12 +3,13 @@ int **allocate_matrix(int rows, int cols) { - int **matrix = malloc(rows * sizeof(int *)); + int **matrix = malloc(rows * sizeof(int *));//creation du tableau X hauteur if (!matrix) return NULL; for (int i = 0; i < rows; i++) { - matrix[i] = malloc(cols * sizeof(int)); + matrix[i] = malloc(cols * sizeof(int));//creation des colonnes + //on free les cols si la matrice n'existe pas if (!matrix[i]) { for (int j = 0; j < i; j++) @@ -24,6 +25,9 @@ void free_matrix(int **matrix, int rows) { if (!matrix) return; + //ajout + for (int j = 0; j < rows; j ++) + free(matrix[j]); free(matrix); return; } @@ -47,5 +51,6 @@ int main(void) } free_matrix(matrix, rows); + //free(matrix); return EXIT_SUCCESS; } diff --git a/AcquiringLand/Fundamentals/magic_arrays.c b/AcquiringLand/Fundamentals/magic_arrays.c index e69de29..069fa11 100644 --- a/AcquiringLand/Fundamentals/magic_arrays.c +++ b/AcquiringLand/Fundamentals/magic_arrays.c @@ -0,0 +1,49 @@ +#include +//#include +int *compress_array(const int *input, int n, int *out_size){ + + if (input == NULL) return NULL; + + int taille = 1; + for (int i = 0; i < n -1; i++) if(input[i] != input[i + 1]) taille ++; + + *out_size = taille * 2; + + + int *rslt = malloc(*out_size * sizeof(int)); + if (rslt == NULL) return NULL; + + + int index_rslt = 0; + int index = 0; + while(index < n){ + + int ch_cons = 0; + int chiffre = input[index]; + + while (index < n && input[index] == chiffre){ + ch_cons ++; + index ++; + } + + rslt[index_rslt ++] = chiffre; + rslt[index_rslt ++] = ch_cons; + + } + + return rslt; + +} +/* +int main(){ + + int test[] = {3, 3, 3, 1, 1, 5, 5, 5, 5}; + int sortie = 6; + int *rs = compress_array(test, 9, &sortie); + + for(int i = 0; i < sortie; i++){ + printf("%i;", rs[i]); + } + free(rs); + +}*/ diff --git a/AcquiringLand/Fundamentals/test b/AcquiringLand/Fundamentals/test deleted file mode 100755 index 3e55db1068e55f4bbf054b0897412730ccfe6811..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19344 zcmeHPdvF}ZneW-vS}RMIWXlGD;k*JH8;)JAY+05K3M<(%BVxe8Hf8h3dbPXKZlQg6 zAGS>K5Xew0j_d3@lHyV((H&fl%GFh<3*nqgawi+k1}X(MMZlp*m69SU=^(^_!#P0M z`+eR0tw)2_x`TWDp;qmD{r$d2_k1(c-P6;pd%HKRcNm7?%iO!Gj*I}lIi2fc&sZQiz4UpD1iuKdztbsm1R z@tdz8(V!`lN@Nz`N7twZzbgFn<0$HopNC&Hep4li7o8HHhgHWKKYHxwd7wDeT9owT zBYjZ)$Pd{K8TUyo!l-U1qAw*X=N+(DUFy)m3qz`>J$04A3uW-0GWhvr@V`ZYQTPgy#X=G2QZPTKBG|L}`d}oQiT1~{xoBqd^=k)G$>`=#??6-pgZ+tAGMLSUGPz(- zsg_a9hLZ7I{LW}57*E1YGBglOL=%bBPVzFfFr3~ESqMVd#B*i!vQd&ry-YNnLRAJ* zp-8Jpga!suVVg)c0qr)B^h;POor~k7BGFtloTGCK-x17bqrp%g>K)8PbNNh??Uhs& z6l`Hs*FqN6D$*I8ai8eRMCnvzHS& zEY)rbLu#$`HAsZwRJZV8DA*TAj1h1FF%?Q}Ry#3a%C(7WH}rI^4KDYsXf0)z`&NqP zOg`Bh&Sx^wWX_x2jZ2_(ONJg?99|>|7Pw zwQ@&WChqMIhrKPWz7;+{nq9QM@m}1NhUL#`$y;#)?HoNRr0ozdBg_59(+9qRX3r^p zuCe@uaWumY@s?5-Y27b#KiWo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