42-archive/fillit/src/libft/ft_strncmp.c
2016-11-04 14:20:58 +01:00

28 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:12 by jhalford #+# #+# */
/* Updated: 2016/11/03 19:14:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int i;
i = 0;
if (!s1 || !s2)
return (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);
}