GCC Code Coverage Report


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

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