Repository navigation
Expand file tree
/
Copy pathft_memcmp.c
More file actions
43 lines (38 loc) · 1.45 KB
/
Copy pathft_memcmp.c
File metadata and controls
43 lines (38 loc) · 1.45 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: spunyapr <spunyapr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 15:49:20 by spunyapr #+# #+# */
/* Updated: 2024/11/27 15:49:21 by spunyapr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
unsigned const char *p;
unsigned const char *t;
i = 0;
p = s1;
t = s2;
if (n == 0)
return (0);
while (p[i] == t[i] && i < (n - 1))
{
i++;
}
return ((unsigned char)p[i] - (unsigned char)t[i]);
}
// int main()
// {
// const char s1[] = "abc";
// const char s2[] = "abcd";
// printf("ft_memcmp = %d\n", ft_memcmp(s1, s2, 4));
// char *s1 = "atoms\0\0\0\0";
// char *s2 = "atoms\0abc";
// size_t size = 8;
// printf("ft_memcmp = %d\n", ft_memcmp(s1, s2, 8));
// }