-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
executable file
·34 lines (31 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: luperez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/05 21:33:09 by luperez #+# #+# */
/* Updated: 2014/11/05 21:59:07 by luperez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *str1;
unsigned char *str2;
int len;
len = (int)n;
if (len < 1)
return (0);
str1 = (unsigned char *)s1;
str2 = (unsigned char *)s2;
while (--len && *str1 == *str2)
{
str1++;
str2++;
}
if (*str1 == *str2)
return (0);
return (*str1 - *str2);
}