Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_str_nbr_unsigned_long | ||
4 | ** File description: | ||
5 | ** Returns the string conversion of a long unsigned number (nb) | ||
6 | */ | ||
7 | /** | ||
8 | * @file my_str_nbr_unsigned_long.c | ||
9 | * @brief The file containing the my_str_nbr_unsigned_long function | ||
10 | * @author Nicolas TORO | ||
11 | */ | ||
12 | |||
13 | #include "my.h" | ||
14 | |||
15 | 1 | static char *set_str_nb_unsigned_long(unsigned long int nb, | |
16 | int int_nb) | ||
17 | { | ||
18 | 1 | char *nb_str = malloc(sizeof(char) * (int_nb + 1)); | |
19 | 1 | int j = 0; | |
20 | 1 | unsigned long int figure_temp = nb; | |
21 | |||
22 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (j = 0; j < int_nb; j++) { |
23 | 2 | nb_str[j] = 48 + (figure_temp % 10); | |
24 | 2 | figure_temp = (figure_temp - (figure_temp % 10)) / 10; | |
25 | } | ||
26 | 1 | nb_str[j] = '\0'; | |
27 | 1 | return my_revstr(nb_str); | |
28 | } | ||
29 | |||
30 | 1 | char *my_str_nbr_unsigned_long(unsigned long int nb) | |
31 | { | ||
32 | 1 | int int_nb = 1; | |
33 | 1 | unsigned long int temp_nb = nb; | |
34 | |||
35 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while ((temp_nb / 10) != 0) { |
36 | 1 | int_nb = int_nb + 1; | |
37 | 1 | temp_nb = temp_nb / 10; | |
38 | } | ||
39 | 1 | return set_str_nb_unsigned_long(nb, int_nb); | |
40 | } | ||
41 |