forked from josanri/Libft_extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
36 lines (33 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aalvarez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/17 00:48:16 by aalvarez #+# #+# */
/* Updated: 2022/08/19 22:09:40 by aalvarez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief compares byte string s1 against byte string s2.
* Both strings are assumed to be n bytes long.
*
* @param s1 the first string to be compared.
* @param s2 the second string to be compared.
* @param n max bytes to be compared.
* @return int the difference between the first differing
* byte (or 0 if any byte differs).
*/
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
i = -1;
while (++i < n)
{
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
}
return (0);
}