-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memcmp.c
48 lines (44 loc) · 1.91 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
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vcodrean <vcodrean@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/19 17:46:53 by vcodrean #+# #+# */
/* Updated: 2022/10/01 10:10:59 by vcodrean ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**Compara los caracteres de dos búferes
* The function ft_memcmp() compares the first n bytes of
* the memory area s1 to the first n bytes of
* the memory area s2
*
* @param void s1 The first string to be compared.
* @param void s2 The string to be compared.
* @param size_t n The number of bytes to compare.
*
* @return The difference between the first two bytes that are different.
*/
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
unsigned const char *str1;
unsigned const char *str2;
i = 0;
str1 = (unsigned const char *)s1;
str2 = (unsigned const char *)s2;
while (i < n) //mientras i < que el tamaño de mi buffer
{
if (*str1 != *str2) // si primer str es diferente del degundo str
{
return ((int)(*str1 - *str2)); // devuelve la diferencia entre los dos strings
}
str1++; //iterammos para poder segir comprobando
str2++;
i++;
}
return (0); //devuelve cero si las dos cadenas son idénticas
//(en caso de no cumplir la condicion del while))
}