-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memcmp.c
More file actions
44 lines (39 loc) · 1.4 KB
/
ft_memcmp.c
File metadata and controls
44 lines (39 loc) · 1.4 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
44
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ibravo-m <ibravo-m@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 15:40:04 by ibravo-m #+# #+# */
/* Updated: 2024/05/02 15:20:24 by ibravo-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// compares de first n bytes of memory between str1 and str2
int ft_memcmp(const void *str1, const void *str2, size_t n)
{
size_t i;
char *s1;
char *s2;
i = 0;
s1 = (char *)str1;
s2 = (char *)str2;
while (i < n)
{
if (s1[i] != s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
i++;
}
return (0);
}
/*int main(void)
{
char s1[] = "ola";
char s2[] = "olA";
int n = 3;
int test = ft_memcmp(s1, s2, n);
int test2 = memcmp(s1, s2, n);
printf("%d\n", test);
printf("%d\n", test2);
}*/