rt/libft/ft_strncmp.c

30 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: scebula <scebula@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/26 09:36:32 by scebula #+# #+# */
/* Updated: 2015/11/27 21:56:31 by scebula ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
while (*s1 && *s1 == *s2 && i < n)
{
s1++;
s2++;
i++;
}
if (i == n)
return (0);
return ((unsigned char)*s1 - (unsigned char)*s2);
}