| 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 | #include "my.h" | ||
| 9 | |||
| 10 | 6 | static void put_str_nb(int nb, int len_nb) | |
| 11 | 6 | { | |
| 12 | 6 | char nb_str[len_nb]; | |
| 13 | 6 | int figure_temp = nb; | |
| 14 | |||
| 15 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 6 times.
|
39 | for (int i = 0; i < len_nb; i++) { |
| 16 | 33 | nb_str[len_nb - i - 1] = 48 + (figure_temp % 10); | |
| 17 | 33 | figure_temp = (figure_temp - (figure_temp % 10)) / 10; | |
| 18 | } | ||
| 19 | 6 | nb_str[len_nb] = '\0'; | |
| 20 | 6 | my_putstr(nb_str); | |
| 21 | 6 | } | |
| 22 | |||
| 23 | 7 | int my_put_nbr(int nb) | |
| 24 | { | ||
| 25 | 7 | int len_nb = 1; | |
| 26 | 7 | int temp_nb = nb; | |
| 27 | |||
| 28 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
|
7 | if (nb == -2147483648) { |
| 29 | 1 | my_putstr("-2147483648"); | |
| 30 | 1 | return 0; | |
| 31 | } | ||
| 32 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
|
6 | if (nb < 0) { |
| 33 | 1 | my_putchar('-'); | |
| 34 | 1 | nb = -nb; | |
| 35 | } | ||
| 36 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 6 times.
|
33 | while ((temp_nb / 10) != 0) { |
| 37 | 27 | len_nb = len_nb + 1; | |
| 38 | 27 | temp_nb = temp_nb / 10; | |
| 39 | } | ||
| 40 | 6 | put_str_nb(nb, len_nb); | |
| 41 | 6 | return 0; | |
| 42 | } | ||
| 43 |