GCC Code Coverage Report


Directory: ./
File: lib/my/my_str_nbr.c
Date: 2024-06-05 00:29:21
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 strings conversion of a number (nb)
6 */
7
8 #include "my.h"
9
10 475 static char *set_str_nb(int nb, int int_nb, int signe)
11 {
12 475 char *nb_str = malloc(sizeof(char) * (int_nb + signe + 1));
13 475 int j = 0;
14 475 int figure_temp = nb;
15
16
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 458 times.
475 if (signe == 1)
17 17 nb_str[int_nb] = '-';
18
2/2
✓ Branch 0 taken 722 times.
✓ Branch 1 taken 475 times.
1197 for (j = 0; j < int_nb; j++) {
19 722 nb_str[j] = 48 + (figure_temp % 10);
20 722 figure_temp = (figure_temp - (figure_temp % 10)) / 10;
21 }
22 475 nb_str[j + signe] = '\0';
23 475 return my_revstr(nb_str);
24 }
25
26 476 char *my_str_nbr(int nb)
27 {
28 476 int int_nb = 1;
29 476 int temp_nb = nb;
30 476 int signe = 0;
31
32
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 475 times.
476 if (nb == -2147483648)
33 1 return "-2147483648";
34
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 458 times.
475 if (nb < 0) {
35 17 signe = 1;
36 17 nb = -nb;
37 }
38
2/2
✓ Branch 0 taken 247 times.
✓ Branch 1 taken 475 times.
722 while ((temp_nb / 10) != 0) {
39 247 int_nb = int_nb + 1;
40 247 temp_nb = temp_nb / 10;
41 }
42 475 return set_str_nb(nb, int_nb, signe);
43 }
44