-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_strcmp.c
38 lines (34 loc) · 827 Bytes
/
my_strcmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
** EPITECH PROJECT, 2022
** My strmpc
** File description:
** Return 0 if str 1 and str 2 are equal,
** -1 if str 1 is lesser than str 2
** and 1 if str 1 is bigger than str 2
*/
int my_strlen(char const *str);
int verif_verdict(int i, int *verdict, char const *s1, char const *s2)
{
if (s1[i] < s2[i]) {
*verdict = -1;
} else if (s1[i] > s2[i]) {
*verdict = 1;
} else {
*verdict = 0;
}
}
int my_strcmp(char const *s1 ,char const *s2)
{
int i = 0;
int verdict = -2;
while (s1[i] != '\0' && s2[i] != '\0' && (verdict == -2 || verdict == 0)) {
verif_verdict(i, &verdict, s1, s2);
i += 1;
}
if (verdict >= -1 && verdict <= 1) {
return (verdict);
} else if (my_strlen(s1) < my_strlen(s2)) {
return (-1);
}
return (1);
}