Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_str_nbr_size_t | ||
4 | ** File description: | ||
5 | ** Returns the strings convertion of a big unsigned number (nb) | ||
6 | */ | ||
7 | |||
8 | #include "my.h" | ||
9 | |||
10 | 24 | static char *set_str_nb(size_t nb, int int_nb) | |
11 | { | ||
12 | 24 | char *nb_str = malloc(sizeof(char) * (int_nb + 1)); | |
13 | 24 | int j = 0; | |
14 | 24 | size_t figure_temp = nb; | |
15 | |||
16 |
2/2✓ Branch 0 taken 353 times.
✓ Branch 1 taken 24 times.
|
377 | for (j = 0; j < int_nb; j++) { |
17 | 353 | nb_str[j] = 48 + (figure_temp % 10); | |
18 | 353 | figure_temp = (figure_temp - (figure_temp % 10)) / 10; | |
19 | } | ||
20 | 24 | nb_str[j] = '\0'; | |
21 | 24 | return my_revstr(nb_str); | |
22 | } | ||
23 | |||
24 | 24 | char *my_str_nbr_size_t(size_t nb) | |
25 | { | ||
26 | 24 | int int_nb = 1; | |
27 | 24 | size_t temp_nb = nb; | |
28 | |||
29 |
2/2✓ Branch 0 taken 329 times.
✓ Branch 1 taken 24 times.
|
353 | while ((temp_nb / 10) != 0) { |
30 | 329 | int_nb = int_nb + 1; | |
31 | 329 | temp_nb = temp_nb / 10; | |
32 | } | ||
33 | 24 | return set_str_nb(nb, int_nb); | |
34 | } | ||
35 |