ft_memcmp

This commit is contained in:
Tanguy MAZE 2018-04-06 17:28:52 +02:00
parent a380be6a68
commit 0e0abea7f0
2 changed files with 31 additions and 1 deletions

View File

@ -6,7 +6,7 @@
# By: tmaze <marvin@42.fr> +#+ +:+ +#+ # # By: tmaze <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2018/04/04 10:51:59 by tmaze #+# #+# # # Created: 2018/04/04 10:51:59 by tmaze #+# #+# #
# Updated: 2018/04/06 16:12:43 by tmaze ### ########.fr # # Updated: 2018/04/06 17:10:28 by tmaze ### ########.fr #
# # # #
#******************************************************************************# #******************************************************************************#
@ -23,6 +23,7 @@ SRCS = \
ft_memccpy.c \ ft_memccpy.c \
ft_memmove.c \ ft_memmove.c \
ft_memchr.c \ ft_memchr.c \
ft_memcmp.c \
ft_strlen.c \ ft_strlen.c \
ft_strdup.c \ ft_strdup.c \
ft_strcpy.c \ ft_strcpy.c \

29
ft_memcmp.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/06 16:55:25 by tmaze #+# #+# */
/* Updated: 2018/04/06 17:27:15 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
int diff;
unsigned char *str1;
unsigned char *str2;
i = 0;
str1 = (unsigned char*)s1;
str2 = (unsigned char*)s2;
diff = str1[0] - str2[0];
while (diff == 0 && ++i < n)
diff = str1[i] - str2[i];
return (diff);
}