-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memcmp.c
35 lines (32 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asarandi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/22 11:12:33 by asarandi #+# #+# */
/* Updated: 2017/09/22 11:17:04 by asarandi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char *u1;
const unsigned char *u2;
size_t i;
u1 = s1;
u2 = s2;
i = 0;
if ((!u1[i]) && (!u2[i]))
return (0);
while (i < n)
{
if (u1[i] != u2[i])
break ;
i++;
}
if (i == n)
return (0);
return (u1[i] - u2[i]);
}