-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memcmp.c
More file actions
33 lines (29 loc) · 1.38 KB
/
ft_memcmp.c
File metadata and controls
33 lines (29 loc) · 1.38 KB
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: fsanz-ex <fsanz-ex@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 19:39:00 by fsanz-ex #+# #+# */
/* Updated: 2023/02/14 15:49:46 by fsanz-ex ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* 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)
{
size_t i;
unsigned char *b1;
unsigned char *b2;
b1 = (unsigned char *) s1;
b2 = (unsigned char *) s2;
i = 0;
if (n == 0)
return (0);
while (b1[i] == b2[i] && i < n - 1)
i++;
return ((int) b1[i] - (int) b2[i]);
}