-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memcmp.c
38 lines (34 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kakiba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/12 00:04:32 by kakiba #+# #+# */
/* Updated: 2022/07/25 22:50:58 by kakiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
unsigned char *buf1;
unsigned char *buf2;
if (n == 0)
return (0);
buf1 = (unsigned char *)s1;
buf2 = (unsigned char *)s2;
i = 0;
while (i < n && buf1[i] == buf2[i])
i++;
if (i == n)
return (0);
return (buf1[i] - buf2[i]);
}
/*
int main()
{
printf("%d\n", memcmp("ok", "a", 0));
printf("%d\n", ft_memcmp("ok", "a", 0));
}*/