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