GCC Code Coverage Report


Directory: ./
File: lib/my/my_str_nbr_base_unsigned.c
Date: 2024-06-05 02:24:39
Exec Total Coverage
Lines: 18 18 100.0%
Functions: 2 2 100.0%
Branches: 6 6 100.0%

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