-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memcmp.c
More file actions
44 lines (40 loc) · 1.44 KB
/
ft_memcmp.c
File metadata and controls
44 lines (40 loc) · 1.44 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: bhielsch <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 10:59:37 by bhielsch #+# #+# */
/* Updated: 2022/10/07 16:30:24 by bhielsch ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <string.h>
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *str1;
unsigned char *str2;
size_t i;
i = 0;
str1 = (unsigned char *)s1;
str2 = (unsigned char *)s2;
while (i != n)
{
if (str1[i] == str2[i])
i++;
else if (str1[i] > str2[i])
return (1);
else
return (-1);
}
return (0);
}
// int main()
// {
// char str1[] = "Hella WorLd";
// char str2[] = "Hella WorLd";
// int n = 100;
// printf("Mine %d \n", ft_memcmp(str1, str2, n));
// printf("OG %d \n", memcmp(str1, str2, n));
// }