GCC Code Coverage Report


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

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