Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2024 | ||
3 | ** my_str_contains | ||
4 | ** File description: | ||
5 | ** Returns 1 if the string (str) contains at least one character from the | ||
6 | ** char list (char_list), 0 otherwise | ||
7 | */ | ||
8 | /** | ||
9 | * @file my_str_contains.c | ||
10 | * @brief The file containing the my_str_contains function | ||
11 | * @author Nicolas TORO | ||
12 | */ | ||
13 | |||
14 | #include "my.h" | ||
15 | |||
16 | 268915 | static int check_char_list(char *str, char *char_list, int i) | |
17 | { | ||
18 |
2/2✓ Branch 0 taken 558636 times.
✓ Branch 1 taken 268737 times.
|
827373 | for (int j = 0; char_list[j] != '\0'; j++) { |
19 |
2/2✓ Branch 0 taken 178 times.
✓ Branch 1 taken 558458 times.
|
558636 | if (str[i] == char_list[j]) |
20 | 178 | return 1; | |
21 | } | ||
22 | 268737 | return 0; | |
23 | } | ||
24 | |||
25 | 19952 | int my_str_contains(char *str, char *char_list) | |
26 | { | ||
27 |
2/4✓ Branch 0 taken 19952 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19952 times.
|
19952 | if (str == NULL || char_list == NULL) |
28 | ✗ | return 0; | |
29 |
2/2✓ Branch 0 taken 268915 times.
✓ Branch 1 taken 19774 times.
|
288689 | for (int i = 0; str[i] != '\0'; i++) { |
30 |
2/2✓ Branch 1 taken 178 times.
✓ Branch 2 taken 268737 times.
|
268915 | if (check_char_list(str, char_list, i)) |
31 | 178 | return 1; | |
32 | } | ||
33 | 19774 | return 0; | |
34 | } | ||
35 |