-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
45 lines (40 loc) · 1.38 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
38
39
40
41
42
43
44
45
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:04:37 by tpouget #+# #+# */
/* Updated: 2020/05/14 17:06:05 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *p1;
unsigned char *p2;
size_t i;
p1 = (unsigned char*)s1;
p2 = (unsigned char*)s2;
i = 0;
while (i < n)
{
if (p1[i] != p2[i])
return (p1[i] - p2[i]);
i++;
}
return (0);
}
/*
#include <string.h>
#include <stdio.h>
int main(int argc, char** argv)
{
char* a1 = argv[1];
char* a2 = argv[2];
printf("Result : %d\n", ft_memcmp(a1, a2, 0));
printf("Result : %d\n", ft_memcmp(a1, a2, 4));
return 0;
}
*/