-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_memcmp.c
37 lines (33 loc) · 1.3 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
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adiaz-lo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/21 13:24:15 by adiaz-lo #+# #+# */
/* Updated: 2020/01/13 12:54:52 by adiaz-lo ### ########.fr */
/* */
/* ************************************************************************** */
/*
** This function compares the first 'n' bytes (each interpreted as unsigned
** char) of the memory areas 's1' & 's2'.
*/
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
unsigned char *str1;
unsigned char *str2;
i = 0;
str1 = (unsigned char*)s1;
str2 = (unsigned char*)s2;
if (!n)
return (0);
while (++i < n && *str1 == *str2)
{
str1++;
str2++;
}
return ((int)(*str1 - *str2));
}