-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
executable file
·36 lines (33 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbensado <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/23 15:02:57 by kbensado #+# #+# */
/* Updated: 2015/12/30 17:14:41 by kbensado ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
int result;
size_t i;
unsigned char *data;
unsigned char *data2;
i = 0;
result = 0;
data = (unsigned char *)s1;
data2 = (unsigned char *)s2;
if (n == 0)
return (0);
while (n--)
{
if (data[i] == data2[i])
i++;
else
return (data[i] - data2[i]);
}
return (result);
}