-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
60 lines (54 loc) · 1.63 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
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbin-jef <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 15:16:01 by sbin-jef #+# #+# */
/* Updated: 2024/08/11 21:44:17 by sbin-jef ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "libft.h"
/*#include <stdio.h>*/
int ft_memcmp(void *str1, void *str2, size_t n)
{
unsigned char *ptr1;
unsigned char *ptr2;
ptr1 = (unsigned char *)str1;
ptr2 = (unsigned char *)str2;
if (ptr1 == NULL || ptr2 == NULL)
{
return (-1);
}
if (n == 0)
return (0);
while (n--)
{
if (*ptr1 != *ptr2)
{
return (*ptr1 - *ptr2);
}
ptr1++;
ptr2++;
}
return (0);
}
/*
int main()
{
char data1[] = "Hello";
char data2[] = "HelLo";
size_t n = 5;
int result = ft_memcmp(data1, data2, n);
if (result < 0) {
printf("data1 is less than data2\n");
} else if (result > 0) {
printf("data1 is greater than data2\n");
} else {
printf("data1 is equal to data2\n");
}
return 0;
}
*/