-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memcmp.c
More file actions
61 lines (53 loc) · 1.73 KB
/
ft_memcmp.c
File metadata and controls
61 lines (53 loc) · 1.73 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mestefan <mestefan@student.42berlin.d +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/19 22:31:06 by mestefan #+# #+# */
/* Updated: 2023/11/19 22:31:09 by mestefan ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
#include "libft.h"
/*
#include <stdio.h>
int ft_memcmp(const void *s1, const void *s2, size_t n);
int main(void)
{
const char *str1 = "Hello";
const char *str2 = "ello";
size_t size = 5;
int result = ft_memcmp(str1, str2, size);
if (result == 0)
{
printf("The memory blocks are equal.\n");
}
else
{
printf("Memory blocks differ at byte index: ");
for (size_t i = 0; i < size; i++)
{
if (str1[i] != str2[i])
{
printf("%zu ", i);
}
}
printf("\n");
}
return 0;
}
*/
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
i++;
}
return (0);
}