-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
38 lines (34 loc) · 1.45 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
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aviholai <aviholai@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/26 16:53:22 by aviholai #+# #+# */
/* Updated: 2022/02/04 15:45:18 by aviholai ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** 'Memcmp()' (memory compare) function compares byte string 's1' against
** byte string 's2'. Both strings are assumed to be 'n' bytes long. Returns
** zero if the two strings are identical, otherwise returns the difference
** between the first two differing bytes.
*/
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
char *string1;
char *string2;
size_t i;
i = 0;
string1 = (char *)s1;
string2 = (char *)s2;
while (i < n)
{
if (string1[i] != string2[i])
return ((unsigned char)string1[i] - (unsigned char)string2[i]);
i++;
}
return (0);
}