Cub3D/libft/ft_strncmp.c
2022-05-03 17:20:10 +02:00

45 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:13:31 by apommier #+# #+# */
/* Updated: 2022/02/14 00:27:01 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int i;
i = 0;
while (n && (s1[i] || s2[i]))
{
if (s1[i] != s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
n--;
i++;
}
return (0);
}
int ft_strcmp(const char *s1, const char *s2)
{
int i;
i = 0;
if (!s1 || !s2)
return (1);
while (s1[i] || s2[i])
{
if (s1[i] != s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
i++;
}
return (0);
}