-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
32 lines (29 loc) · 1.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: albarret <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/09 20:36:35 by albarret #+# #+# */
/* Updated: 2018/11/12 21:14:32 by albarret ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
unsigned char *ptr;
unsigned char *ptr2;
if (n == 0)
return (0);
ptr = (unsigned char*)s1;
ptr2 = (unsigned char*)s2;
i = 0;
while (*ptr == *ptr2 && ++i < n)
{
ptr++;
ptr2++;
}
return ((int)(*ptr - *ptr2));
}