GCC Code Coverage Report


Directory: ./
File: lib/my/my_putnbr_base.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 2 2 100.0%
Branches: 8 8 100.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_putnbr_base
4 ** File description:
5 ** Prints a number (nb) in the requested base (base) in stdout
6 */
7 /**
8 * @file my_putnbr_base.c
9 * @brief The file containing the my_putnbr_base function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 8 static void put_str_nb(int nb, int len_nb, char const *base, int base_len)
16 8 {
17 8 char nb_str[len_nb];
18 8 int figure_temp = nb;
19
20
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 for (int i = 0; i < len_nb; i++) {
21 12 nb_str[len_nb - i - 1] = base[figure_temp % base_len];
22 12 figure_temp = (figure_temp - (figure_temp % base_len)) / base_len;
23 }
24 8 nb_str[len_nb] = '\0';
25 8 my_putstr(nb_str);
26 8 }
27
28 8 void my_putnbr_base(int nbr, char const *base)
29 {
30 8 int len_nb = 1;
31 8 int temp_nb = nbr;
32 8 int base_len = 0;
33
34
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (nbr < 0) {
35 1 my_putchar('-');
36 1 nbr = -nbr;
37 }
38
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 8 times.
130 while (base[base_len] != '\0') {
39 122 base_len = base_len + 1;
40 }
41
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 while ((temp_nb / base_len) != 0) {
42 4 len_nb = len_nb + 1;
43 4 temp_nb = temp_nb / base_len;
44 }
45 8 put_str_nb(nbr, len_nb, base, base_len);
46 8 }
47