blob: a1e18da6e4cee073a75da231cf8b7db9daf305c0 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 15:54:13 by dkaiser #+# #+# */
/* Updated: 2024/03/06 19:45:09 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
int result;
i = 0;
result = 0;
while (!result && i < n)
{
result = *((unsigned char *)s1 + i) - *((unsigned char *)s2 + i);
i++;
}
return (result);
}
/* #include <stdio.h> */
/* int main(void) */
/* { */
/* char str1[] = "Hello"; */
/* char str2[] = "Hellu"; */
/* printf("memcmp: %d\n", memcmp(str1, str2, 5)); */
/* printf("ft_memcmp: %d\n", ft_memcmp(str1, str2, 5)); */
/* } */
|