ft_malloc/libft/ft_strncmp.c
2025-11-28 19:50:58 +01:00

26 lines
1.1 KiB
C
Executable file

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 17:12:52 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:55 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
while (n && *s1 && (*s1 == *s2))
{
s1++;
s2++;
n--;
}
if (n == 0)
return (0);
return ((const unsigned char)*s1 - (const unsigned char)*s2);
}