| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2024 | ||
| 3 | ** my_strict_find_nbr | ||
| 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_find_nbr.c | ||
| 10 | * @brief The file containing the my_strict_find_nbr function | ||
| 11 | * @author Nicolas TORO | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include "my.h" | ||
| 15 | |||
| 16 | 12 | int my_strict_find_nbr(char const *str) | |
| 17 | { | ||
| 18 | 12 | int nb = -1; | |
| 19 | 12 | int start = -1; | |
| 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 19 times.
✓ Branch 1 taken 1 times.
|
20 | for (int index = 0; str[index] != '\0'; index++) { |
| 24 |
6/6✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 2 times.
|
19 | if (start == -1 && str[index] >= '1' && str[index] <= '9') { |
| 25 | 4 | start = index; | |
| 26 | 4 | nb = 0; | |
| 27 | } | ||
| 28 |
6/6✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 2 times.
|
19 | if (nb < -1 || str[index] < '0' || str[index] > '9' || |
| 29 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9 | (index > start + 8 && str[start] != '1' && str[start] != '2')) |
| 30 | 10 | return nb; | |
| 31 | 9 | nb = nb * 10 + (str[index] - 48); | |
| 32 | } | ||
| 33 | 1 | return nb; | |
| 34 | } | ||
| 35 |