-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
executable file
·38 lines (35 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gyong-si <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/12 16:29:22 by gyong-si #+# #+# */
/* Updated: 2023/09/22 20:50:26 by gyong-si ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
int ft_memcmp(const void *str1, const void *str2, size_t n)
{
const unsigned char *str1_char;
const unsigned char *str2_char;
size_t i;
i = 0;
str1_char = (const unsigned char *)str1;
str2_char = (const unsigned char *)str2;
while (i < n)
{
if (str1_char[i] > str2_char[i])
{
return (1);
}
else if (str1_char[i] < str2_char[i])
{
return (-1);
}
i++;
}
return (0);
}