Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_str_nbr_base_unsigned | ||
4 | ** File description: | ||
5 | ** Returns the strings conversion of | ||
6 | ** an unsigned number (nbr) in specific base (base) | ||
7 | */ | ||
8 | |||
9 | #include "my.h" | ||
10 | |||
11 | 1 | static char *put_str_nb(long long int nb, int len_nb, | |
12 | char const *base, int base_len) | ||
13 | { | ||
14 | 1 | char *nb_str = malloc(sizeof(char) * (len_nb + 1)); | |
15 | 1 | long long int figure_temp = nb; | |
16 | |||
17 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (int i = 0; i < len_nb; i++) { |
18 | 2 | nb_str[len_nb - i - 1] = base[figure_temp % base_len]; | |
19 | 2 | figure_temp = (figure_temp - (figure_temp % base_len)) / base_len; | |
20 | } | ||
21 | 1 | nb_str[len_nb] = '\0'; | |
22 | 1 | return nb_str; | |
23 | } | ||
24 | |||
25 | 1 | char *my_str_nbr_base_long_long_int(long long int nbr, char const *base) | |
26 | { | ||
27 | 1 | int len_nb = 1; | |
28 | 1 | long long int temp_nb = nbr; | |
29 | 1 | int base_len = 0; | |
30 | |||
31 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | while (base[base_len] != '\0') { |
32 | 10 | base_len = base_len + 1; | |
33 | } | ||
34 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while ((temp_nb / base_len) != 0) { |
35 | 1 | len_nb = len_nb + 1; | |
36 | 1 | temp_nb = temp_nb / base_len; | |
37 | } | ||
38 | 1 | return put_str_nb(nbr, len_nb, base, base_len); | |
39 | } | ||
40 |