-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
42 lines (39 loc) · 1.38 KB
/
ft_memcmp.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
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gudaniel <gudaniel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 13:57:08 by gudaniel #+# #+# */
/* Updated: 2024/04/09 14:01:28 by gudaniel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char *p1;
const unsigned char *p2;
size_t i;
i = 0;
p1 = (const unsigned char *)s1;
p2 = (const unsigned char *)s2;
while (i < n)
{
if (p1[i] < p2[i])
return (-1);
else if (p1[i] > p2[i])
return (1);
i++;
}
return (0);
}
/* int main()
{
char str1[] = "Hello";
char str2[] = "aello";
int n = 5;
printf("%d\n", ft_memcmp(str1, str2, n));
printf("%d\n", memcmp(str1, str2, n));
return (0);
} */