| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2024 | ||
| 3 | ** my_strict_getnbr | ||
| 4 | ** File description: | ||
| 5 | ** Returns an int number starting from a string number (str) and -1 if the | ||
| 6 | ** string is not an exact positive number | ||
| 7 | */ | ||
| 8 | /** | ||
| 9 | * @file my_strict_getnbr.c | ||
| 10 | * @brief The file containing the my_strict_getnbr function | ||
| 11 | * @author Nicolas TORO | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include "my.h" | ||
| 15 | |||
| 16 | 12 | int my_strict_getnbr(char const *str) | |
| 17 | { | ||
| 18 | 12 | int nb = 0; | |
| 19 | 12 | int start = 0; | |
| 20 | |||
| 21 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | if (str[0] == '\0') |
| 22 | 1 | return -1; | |
| 23 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2 times.
|
30 | for (int index = 0; str[index] != '\0'; index++) { |
| 24 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 3 times.
|
28 | if (str[index] != '0') |
| 25 | 25 | start = index; | |
| 26 |
5/6✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 19 times.
✓ Branch 5 taken 2 times.
|
28 | if (nb < 0 || str[index] < '0' || str[index] > '9' || |
| 27 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
19 | (index > start + 8 && str[start] != '1' && str[start] != '2')) |
| 28 | 9 | return -1; | |
| 29 | 19 | nb = nb * 10 + (str[index] - 48); | |
| 30 | } | ||
| 31 | 2 | return nb; | |
| 32 | } | ||
| 33 |