printf/libft/src/ft_strncmp.c

35 lines
1.2 KiB
C
Raw Normal View History

2023-04-15 06:55:33 +02:00
/* ************************************************************************** */
/* */
/* :::::::: */
2023-10-26 18:32:55 +02:00
/* ft_strncmp.c :+: :+: */
2023-04-15 06:55:33 +02:00
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/01 19:09:01 by djonker #+# #+# */
2023-10-26 18:32:55 +02:00
/* Updated: 2023/10/18 17:00:19 by houtworm ######## odam.nl */
2023-04-15 06:55:33 +02:00
/* */
/* ************************************************************************** */
#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);
}