42-archive/libftasm/srcs/str/ft_strncmp.c
2017-03-31 18:21:20 +02:00

26 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:12 by jhalford #+# #+# */
/* Updated: 2016/11/03 16:11:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int i;
i = 0;
while (*(s1 + i) && *(s1 + i) == *(s2 + i) && i < (int)n)
i++;
if (i < (int)n)
return (*((unsigned char*)s1 + i) - *((unsigned char*)s2 + i));
else
return (0);
}