-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_memcmp.c
33 lines (30 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sel-mlil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 02:12:31 by sel-mlil #+# #+# */
/* Updated: 2024/11/01 23:14:59 by sel-mlil ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
const unsigned char *_s1;
const unsigned char *_s2;
if (n == 0)
return (0);
i = 0;
_s1 = (unsigned char *)s1;
_s2 = (unsigned char *)s2;
while (i < n)
{
if (_s1[i] != _s2[i])
return (_s1[i] - _s2[i]);
i++;
}
return (0);
}