-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memcmp.c
36 lines (33 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysoroko <ysoroko@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/17 09:39:58 by ysoroko #+# #+# */
/* Updated: 2020/11/30 18:36:36 by ysoroko ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *str1, const void *str2, size_t n)
{
size_t i;
unsigned char *my_str1;
unsigned char *my_str2;
i = 0;
my_str1 = (unsigned char *)(str1);
my_str2 = (unsigned char *)(str2);
while (my_str1[i] == my_str2[i] && i < n - 1)
{
i++;
}
if (i >= n)
{
return (0);
}
else
{
return (my_str1[i] - my_str2[i]);
}
}