Files
mmoat/lib/libft/srcs/str/ft_strncmp.c
gazhonsepaskwa 09c2cb5b3e base struct
2025-01-13 13:21:53 +01:00

34 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 10:58:07 by nalebrun #+# #+# */
/* Updated: 2024/11/25 16:16:32 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
unsigned char *ss1;
unsigned char *ss2;
if (!s1 || !s2)
return (0);
i = 0;
ss1 = (unsigned char *)s1;
ss2 = (unsigned char *)s2;
if (n == 0)
return (0);
while (i < n && ss1[i] && ss2[i] && ss1[i] == ss2[i])
i++;
if (i == n)
return (0);
return (ss1[i] - ss2[i]);
}