33 lines
1.2 KiB
C
33 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strncmp.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/05/21 06:55:09 by lfirmin #+# #+# */
|
|
/* Updated: 2024/05/24 08:47:59 by lfirmin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#include "libft.h"
|
|
|
|
int ft_strncmp(const char *s1, const char *s2, unsigned int n)
|
|
{
|
|
unsigned int i;
|
|
unsigned char c1;
|
|
unsigned char c2;
|
|
|
|
i = 0;
|
|
if (n == 0)
|
|
return (0);
|
|
while (i < n)
|
|
{
|
|
c1 = (unsigned char)s1[i];
|
|
c2 = (unsigned char)s2[i];
|
|
if (c1 != c2 || c1 == '\0' || c2 == '\0')
|
|
return (c1 - c2);
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|