-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memcmp.c
More file actions
41 lines (38 loc) · 1.49 KB
/
ft_memcmp.c
File metadata and controls
41 lines (38 loc) · 1.49 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
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jowagner <jowagner@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 14:02:17 by jowagner #+# #+# */
/* Updated: 2024/12/12 19:49:28 by jowagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Compares the first n bytes of two memory areas.
*
* @param ptr1 Pointer to the first memory block.
* @param ptr2 Pointer to the second memory block.
* @param n Number of bytes to compare;
* @return an integer indicating the result of the comparison.
*/
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned const char *s1_data;
unsigned const char *s2_data;
s1_data = (unsigned char *)s1;
s2_data = (unsigned char *)s2;
if (n == 0)
return (0);
while (n)
{
if (*s1_data != *s2_data)
return (*s1_data - *s2_data);
n--;
s1_data++;
s2_data++;
}
return (0);
}