-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memcmp.c
More file actions
44 lines (38 loc) · 1.38 KB
/
ft_memcmp.c
File metadata and controls
44 lines (38 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atimoshe <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/29 16:51:36 by atimoshe #+# #+# */
/* Updated: 2020/02/29 17:33:28 by atimoshe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
unsigned char *ps1;
unsigned char *ps2;
i = 0;
ps1 = (unsigned char *)s1;
ps2 = (unsigned char *)s2;
while (i < n)
{
if (ps1[i] == ps2[i])
i++;
return (ps1[i] - ps2[i]);
}
return (0);
}
int main(void)
{
char str1[] = "g";
char str2[] = "gg";
size_t len = 2;
printf("Orig ver - %d\n", memcmp(str1, str2, len));
printf("Mine ver - %d\n", ft_memcmp(str1, str2, len));
return (0);
}