| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2023 | ||
| 3 | ** my_strncmp | ||
| 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_strncmp.c | ||
| 10 | * @brief The file containing the my_strncmp function | ||
| 11 | * @author Nicolas TORO | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include "my.h" | ||
| 15 | |||
| 16 | 144677 | int my_strncmp(char const *s1, char const *s2, int n) | |
| 17 | { | ||
| 18 | 144677 | int i = 0; | |
| 19 | |||
| 20 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 144675 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
144677 | if (s1 == NULL && s2 == NULL) |
| 21 | 1 | return 0; | |
| 22 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 144675 times.
|
144676 | if (s1 == NULL) |
| 23 | 1 | return 0 - s2[0]; | |
| 24 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 144674 times.
|
144675 | if (s2 == NULL) |
| 25 | 1 | return s1[0] - 0; | |
| 26 |
4/6✓ Branch 0 taken 150258 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 150258 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 109588 times.
✓ Branch 5 taken 40670 times.
|
150258 | while (s1[i] != '\0' && s2[i] != '\0' && i + 1 < n) { |
| 27 |
2/2✓ Branch 0 taken 51660 times.
✓ Branch 1 taken 57928 times.
|
109588 | if (s1[i] < s2[i]) |
| 28 | 51660 | return s1[i] - s2[i]; | |
| 29 |
2/2✓ Branch 0 taken 52344 times.
✓ Branch 1 taken 5584 times.
|
57928 | if (s1[i] > s2[i]) |
| 30 | 52344 | return s1[i] - s2[i]; | |
| 31 | 5584 | i++; | |
| 32 | } | ||
| 33 | 40670 | return s1[i] - s2[i]; | |
| 34 | } | ||
| 35 |