eg
This commit is contained in:
@@ -3,7 +3,15 @@
|
|||||||
|
|
||||||
int *division(int input, int by)
|
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;
|
int *ptr = &value;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 *));
|
char **rslt = malloc((*array_size + 1 )* sizeof(char *));
|
||||||
|
if(rslt == NULL) return NULL;
|
||||||
|
|
||||||
int index_clc = 0;
|
int index_clc = 0;
|
||||||
|
int index_clc2 = 0;
|
||||||
//char *temp;
|
//char *temp;
|
||||||
|
|
||||||
while (index_clc < *array_size){
|
while (index_clc < *array_size + 1){
|
||||||
|
|
||||||
|
|
||||||
if (index_clc == index){
|
if (index_clc == index) *(rslt + index_clc) = insert_str;
|
||||||
*(rslt + index_clc) = insert_str;
|
|
||||||
index_clc ++;
|
|
||||||
}
|
|
||||||
else{
|
else{
|
||||||
*(rslt + index_clc) = *(strings_array + index_clc);
|
*(rslt + index_clc) = *(strings_array + index_clc2);
|
||||||
}
|
index_clc2 ++;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (index_clc >= index){
|
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;
|
//*(strings_array + index) = insert_str;
|
||||||
|
|
||||||
//free(temp);
|
//free(temp);
|
||||||
|
*array_size = *array_size + 1;
|
||||||
return rslt;
|
return rslt;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int main(){
|
int main(){
|
||||||
char *tests[] = {"This", "is", "a", "long", "example"};
|
char *tests[] = {"This", "is", "a", "long", "example"};
|
||||||
char *ins = "very";
|
char *ins = "very";
|
||||||
int ted = 5;
|
int ted = 5;
|
||||||
|
|
||||||
char **rslt = insert_string(tests, &ted, ins ,3);
|
char **rslt = insert_string(tests, &ted, ins ,3);
|
||||||
int index = 0;
|
|
||||||
while (index < 6){
|
if(rslt != NULL){
|
||||||
printf("%s", *(rslt + index));
|
|
||||||
index ++;
|
for (int i = 0; i < ted; i ++) printf("%s",rslt[i]);
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
free (rslt);
|
free (rslt);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ char *my_itoa(int value){
|
|||||||
int taille = get_number_length(value);
|
int taille = get_number_length(value);
|
||||||
|
|
||||||
char *rslt = malloc(taille + 1 * sizeof(char));
|
char *rslt = malloc(taille + 1 * sizeof(char));
|
||||||
|
if (rslt == NULL) return NULL;
|
||||||
|
|
||||||
if (value < 0){
|
if (value < 0){
|
||||||
value = value * -1;
|
value = value * -1;
|
||||||
@@ -46,7 +47,7 @@ char *my_itoa(int value){
|
|||||||
|
|
||||||
return rslt;
|
return rslt;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int main(){
|
int main(){
|
||||||
printf("TESTS 1 \n");
|
printf("TESTS 1 \n");
|
||||||
printf("%i\n", get_number_length(7)); //1
|
printf("%i\n", get_number_length(7)); //1
|
||||||
@@ -66,4 +67,4 @@ int main(){
|
|||||||
printf("%s\n", rslt);
|
printf("%s\n", rslt);
|
||||||
free(rslt);
|
free(rslt);
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
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);
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|||||||
@@ -3,12 +3,13 @@
|
|||||||
|
|
||||||
int **allocate_matrix(int rows, int cols)
|
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)
|
if (!matrix)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (int i = 0; i < rows; i++)
|
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])
|
if (!matrix[i])
|
||||||
{
|
{
|
||||||
for (int j = 0; j < i; j++)
|
for (int j = 0; j < i; j++)
|
||||||
@@ -24,6 +25,9 @@ void free_matrix(int **matrix, int rows)
|
|||||||
{
|
{
|
||||||
if (!matrix)
|
if (!matrix)
|
||||||
return;
|
return;
|
||||||
|
//ajout
|
||||||
|
for (int j = 0; j < rows; j ++)
|
||||||
|
free(matrix[j]);
|
||||||
free(matrix);
|
free(matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -47,5 +51,6 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
free_matrix(matrix, rows);
|
free_matrix(matrix, rows);
|
||||||
|
//free(matrix);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
//#include <stdio.h>
|
||||||
|
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);
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|||||||
Binary file not shown.
@@ -51,6 +51,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
printf("%s",res1);
|
||||||
puts(res1);
|
puts(res1);
|
||||||
free(res1);
|
free(res1);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|||||||
Reference in New Issue
Block a user