printf/libft/src/ft_strncmp.c
2023-10-26 18:32:55 +02:00

35 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strncmp.c :+: :+: */
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/01 19:09:01 by djonker #+# #+# */
/* Updated: 2023/10/18 17:00:19 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
if (s1 == NULL && s2 == NULL)
return (0);
if (s1 == NULL || s2 == NULL)
return (1);
if (n == 0)
return (0);
while (n)
{
if (*s1 != *s2)
return (*(unsigned char *)s1 - *(unsigned char *)s2);
if (*s1 == '\0')
break ;
s1++;
s2++;
n--;
}
return (0);
}