| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2023 | ||
| 3 | ** my_strcmp | ||
| 4 | ** File description: | ||
| 5 | ** Returns 0 if the strings (s1 and s2) are identical, | ||
| 6 | ** otherwise it returns the difference | ||
| 7 | */ | ||
| 8 | /** | ||
| 9 | * @file my_strcmp.c | ||
| 10 | * @brief The file containing the my_strcmp function | ||
| 11 | * @author Nicolas TORO | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include "my.h" | ||
| 15 | |||
| 16 | 229708 | int my_strcmp(char const *s1, char const *s2) | |
| 17 | { | ||
| 18 | 229708 | int i = 0; | |
| 19 | |||
| 20 |
4/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 229700 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7 times.
|
229708 | if (s1 == NULL && s2 == NULL) |
| 21 | 1 | return 0; | |
| 22 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 229700 times.
|
229707 | if (s1 == NULL) |
| 23 | 7 | return 0 - s2[0]; | |
| 24 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 229699 times.
|
229700 | if (s2 == NULL) |
| 25 | 1 | return s1[0] - 0; | |
| 26 |
4/4✓ Branch 0 taken 235490 times.
✓ Branch 1 taken 1017 times.
✓ Branch 2 taken 234202 times.
✓ Branch 3 taken 1288 times.
|
236507 | while (s1[i] != '\0' && s2[i] != '\0') { |
| 27 |
2/2✓ Branch 0 taken 123826 times.
✓ Branch 1 taken 110376 times.
|
234202 | if (s1[i] < s2[i]) |
| 28 | 123826 | return -1; | |
| 29 |
2/2✓ Branch 0 taken 103568 times.
✓ Branch 1 taken 6808 times.
|
110376 | if (s1[i] > s2[i]) |
| 30 | 103568 | return s1[i] - s2[i]; | |
| 31 | 6808 | i++; | |
| 32 | } | ||
| 33 | 2305 | return s1[i] - s2[i]; | |
| 34 | } | ||
| 35 |