libft_old/extended_libft/ft_strncmp.c
Willem Haffmans 326f52308e all
2024-07-26 22:32:04 +02:00

30 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 18:42:11 by whaffman #+# #+# */
/* Updated: 2024/07/10 14:51:24 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
if (n == 0)
return (0);
while (*s1 && *s1 == *s2 && i < n - 1)
{
s1++;
s2++;
i++;
}
return ((unsigned char) *s1 - (unsigned char) *s2);
}