-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcmp.c
32 lines (30 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: estettle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 21:41:37 by estettle #+# #+# */
/* Updated: 2024/09/27 21:44:54 by estettle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
/* ft_memcmp()
* compares two memory areas *s1 and *s2 for n bytes and tries to find a
* difference.
* if found, it returns the size difference between both bytes as unsigned chars
* if not, it returns 0.
*/
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
while (n > 0)
{
if (*(unsigned char *)s1 != *(unsigned char *)s2)
return (*(unsigned char *)s1 - *(unsigned char *)s2);
n--;
s1++;
s2++;
}
return (0);
}