This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_memcmp.c
40 lines (35 loc) · 1.54 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
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <mcombeau@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/25 22:41:23 by mcombeau #+# #+# */
/* Updated: 2021/12/02 16:51:42 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
DESCRIPTION :
The function ft_memcmp compares the first n bytes of the memory areas
s1 and s2. The bytes are interpreted as unsigned char.
RETURN VALUE :
An integer less than, equal to, or greater than zero if the first
n bytes of s1 is found to be less than, equal to, or greater than the
first n bytes of s2. Zero if n is equal to zero.
*/
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
const char *str1;
const char *str2;
size_t i;
if (n == 0)
return (0);
str1 = (const char *)s1;
str2 = (const char *)s2;
i = 0;
while ((i < n - 1) && str1[i] == str2[i])
i++;
return ((unsigned char)str1[i] - (unsigned char)str2[i]);
}