Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_getnbr | ||
4 | ** File description: | ||
5 | ** get str in number | ||
6 | */ | ||
7 | |||
8 | #include "my.h" | ||
9 | |||
10 | 102 | static int index_negative(char const *str, int index, int index_neg) | |
11 | { | ||
12 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 91 times.
|
102 | if (str[index - 1] == '-') |
13 | 11 | index_neg = (-1); | |
14 | 102 | return index_neg; | |
15 | } | ||
16 | |||
17 | 104 | int my_getnbr(char const *str) | |
18 | { | ||
19 | 104 | int convert = 0; | |
20 | 104 | int index = 0; | |
21 | 104 | int index_neg = 1; | |
22 | 104 | int index_int = 0; | |
23 | |||
24 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 103 times.
|
104 | if (my_strcmp(str, "-2147483648") == 0) |
25 | 1 | return -2147483648; | |
26 |
6/6✓ Branch 0 taken 102 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 101 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
|
103 | if ((str[0] < '0' || str[0] > '9') && str[0] != '-') |
27 | 1 | return 0; | |
28 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 102 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 102 times.
|
103 | while (str[index] < '0' || str[index] > '9') |
29 | 1 | index++; | |
30 | 102 | index_neg = index_negative(str, index, index_neg); | |
31 |
4/4✓ Branch 0 taken 271 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 201 times.
✓ Branch 3 taken 70 times.
|
303 | while (str[index] >= '0' && str[index] <= '9') { |
32 | 201 | convert = convert * 10 + (str[index] - 48); | |
33 | 201 | index++; | |
34 | 201 | index_int++; | |
35 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 200 times.
|
201 | if (index_int > 10) |
36 | 1 | convert = 0; | |
37 | } | ||
38 | 102 | return index_neg * convert; | |
39 | } | ||
40 |