-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memcmp.c
37 lines (34 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akdemir <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/09 20:41:56 by akdemir #+# #+# */
/* Updated: 2023/07/14 17:37:19 by akdemir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *p_s1;
unsigned char *p_s2;
unsigned int i;
p_s1 = (unsigned char *)s1;
p_s2 = (unsigned char *)s2;
i = 0;
while (i < n)
{
if (p_s1[i] != p_s2[i])
return ((unsigned char)p_s1[i] - (unsigned char)p_s2[i]);
i++;
}
return (0);
}
int main()
{
char s1[]="akif";
char s2[]="akiz";
printf("%d",ft_memcmp(s1,s2,4));
}