-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
32 lines (29 loc) · 1.23 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: jcuzin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 16:06:57 by jcuzin #+# #+# */
/* Updated: 2022/11/29 17:04:10 by jcuzin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t cursor;
unsigned char *ptr1;
unsigned char *ptr2;
cursor = 0;
ptr1 = (unsigned char *)s1;
ptr2 = (unsigned char *)s2;
while (cursor < n)
{
if (ptr1[cursor] == ptr2[cursor] && cursor < n)
cursor++;
else
return (ptr1[cursor] - ptr2[cursor]);
}
return (0);
}