ee
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char **insert_string(char **strings_array, int *array_size, char *insert_str, int index){
|
||||||
|
|
||||||
|
|
||||||
|
char **rslt = malloc(array_size + 1 * sizeof(char));
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
while (*(strings_array + index)){
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int get_number_length(int value){
|
||||||
|
|
||||||
|
if (value > 0 && value < 10) return 1;
|
||||||
|
|
||||||
|
int clc = 0;
|
||||||
|
if (value < 0) {
|
||||||
|
value = value * -1;
|
||||||
|
clc ++;
|
||||||
|
}
|
||||||
|
while (value > 10 ){
|
||||||
|
clc ++;
|
||||||
|
value = value / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return clc + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *my_itoa(int value){
|
||||||
|
|
||||||
|
int taille = get_number_length(value);
|
||||||
|
|
||||||
|
char *rslt = malloc(taille + 1 * sizeof(char));
|
||||||
|
|
||||||
|
if (value < 0){
|
||||||
|
value = value * -1;
|
||||||
|
*rslt = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
*(rslt + taille) = '\0';
|
||||||
|
|
||||||
|
if(value < 10){
|
||||||
|
if( *rslt == '-')*(rslt + 1) = value + 48;
|
||||||
|
else *(rslt) = value + 48;
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
taille --;
|
||||||
|
while (taille > 0){
|
||||||
|
*(rslt + taille) = 48 +value % 10;
|
||||||
|
value = value / 10;
|
||||||
|
taille --;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
printf("TESTS 1 \n");
|
||||||
|
printf("%i\n", get_number_length(7)); //1
|
||||||
|
printf("%i\n",get_number_length(-97163)); //6
|
||||||
|
printf("%i\n",get_number_length(82622)); //5
|
||||||
|
|
||||||
|
printf("TESTS 2\n");
|
||||||
|
char *rslt = "";
|
||||||
|
|
||||||
|
rslt = my_itoa(-172); // "-172"
|
||||||
|
printf("%s\n", rslt);
|
||||||
|
free(rslt);
|
||||||
|
rslt = my_itoa(2); // "2"
|
||||||
|
printf("%s\n", rslt);
|
||||||
|
free(rslt);
|
||||||
|
rslt = my_itoa(-2829302); // "-2829302"
|
||||||
|
printf("%s\n", rslt);
|
||||||
|
free(rslt);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -101,7 +101,7 @@ void hash_map_free(struct hash_map *hash_map)
|
|||||||
}
|
}
|
||||||
free(hash_map->data);
|
free(hash_map->data);
|
||||||
free(hash_map);
|
free(hash_map);
|
||||||
hash_map->data = NULL;
|
//hash_map->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hash_map_dump(struct hash_map *hash_map)
|
void hash_map_dump(struct hash_map *hash_map)
|
||||||
@@ -160,8 +160,9 @@ bool hash_map_remove(struct hash_map *hash_map, const char *key)
|
|||||||
prev->next = elt->next;
|
prev->next = elt->next;
|
||||||
else
|
else
|
||||||
hash_map->data[hashed_val] = elt->next;
|
hash_map->data[hashed_val] = elt->next;
|
||||||
free(elt);
|
//free(elt);
|
||||||
printf("removed %s", elt->value);
|
printf("removed %s", elt->value);
|
||||||
|
free(elt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user