-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
55 lines (51 loc) · 1.54 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
46
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yeparra- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/27 20:00:04 by yeparra- #+# #+# */
/* Updated: 2023/09/29 12:59:29 by yeparra- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *cs, const void *ct, size_t n)
{
const unsigned char *ucs;
const unsigned char *uct;
size_t i;
ucs = cs;
uct = ct;
i = 0;
while (i < n)
{
if (ucs[i] != uct[i])
{
return (ucs[i] - uct[i]);
}
i++;
}
return (0);
}
/*
int main()
{
char s1[] = "hello";
char s2[] = "hellx";
size_t n = 4;
int cmp = ft_memcmp(s1, s2, n);
if(cmp < 0)
{
printf("Las primeras '%zu' bytes de s1 son menores que las de s2.\n", n);
}
else if(cmp > 0)
{
printf("Las primeras '%zu' bytes de s1 son mayores que las de s2.\n", n);
}
else
{
printf("Las primeras '%zu' bytes de s1 y s2 son iguales.\n", n);
}
return (0);
}*/