libft/ft_memcmp.c

49 lines
1.4 KiB
C
Raw Permalink Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 15:26:08 by kcolin #+# #+# */
/* Updated: 2024/10/16 15:31:27 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
i = 0;
while (1)
{
if (i >= n)
return (0);
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
break ;
i++;
}
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
}
/*
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
size_t cmp_len;
cmp_len = 0;
if (argc > 2)
{
printf("mine: %d\tlib: %d\n",
ft_memcmp(argv[1], argv[2], cmp_len),
memcmp(argv[1], argv[2], cmp_len));
}
return (0);
}
*/