-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memcmp.c
More file actions
43 lines (38 loc) · 1.42 KB
/
ft_memcmp.c
File metadata and controls
43 lines (38 loc) · 1.42 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gsaiago <gsaiago@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/30 19:00:17 by gsaiago #+# #+# */
/* Updated: 2022/06/15 21:08:51 by gsaiago ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
const char *str1;
const char *str2;
str1 = s1;
str2 = s2;
i = -1;
if (n == 0)
return (0);
while (++i < n)
if (str1[i] != str2[i])
return (((unsigned char *)str1)[i] - ((unsigned char *)str2)[i]);
return (0);
}
/*
int main(void)
{
char str1[] = "Essa aqui";
char str2[] = "Essa aqui";
printf("str1 > %s\n", str1);
printf("str2 > %s\n", str2);
printf("memcmp > %d\n", memcmp(str1, str2, 50));
printf("ft_memcmp > %d\n", ft_memcmp(str1, str2, 50));
}
*/