34 lines
1.2 KiB
C
34 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strncmp.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/07/18 19:09:01 by erey-bet #+# #+# */
|
|
/* Updated: 2022/10/05 15:04:46 by erey-bet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
|
{
|
|
size_t i;
|
|
unsigned char *tmp_s1;
|
|
unsigned char *tmp_s2;
|
|
|
|
if (n <= 0)
|
|
return (0);
|
|
tmp_s1 = (unsigned char *)s1;
|
|
tmp_s2 = (unsigned char *)s2;
|
|
i = 1;
|
|
while (*tmp_s1 == *tmp_s2 && (*tmp_s1 != '\0' && *tmp_s2 != '\0') && i < n)
|
|
{
|
|
tmp_s1++;
|
|
tmp_s2++;
|
|
i++;
|
|
}
|
|
return (*tmp_s1 - *tmp_s2);
|
|
}
|