42_libft/ft_strncmp.c

26 lines
1.1 KiB
C
Raw Permalink Normal View History

2022-09-27 10:29:23 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 08:30:26 by cchauvet #+# #+# */
2022-10-04 08:21:55 -04:00
/* Updated: 2022/09/28 17:29:56 by cchauvet ### ########.fr */
2022-09-27 10:29:23 -04:00
/* */
/* ************************************************************************** */
#include "libft.h"
2022-10-04 08:21:55 -04:00
int ft_strncmp(const char *s1, const char *s2, size_t n)
2022-09-27 10:29:23 -04:00
{
size_t i;
2022-10-04 08:21:55 -04:00
if (n == 0)
return (0);
2022-09-27 10:29:23 -04:00
i = 0;
while (s1[i] == s2[i] && i < n - 1 && s1[i] && s2[i])
i++;
2022-10-04 08:21:55 -04:00
return ((unsigned char) s1[i] - (unsigned char) s2[i]);
2022-09-27 10:29:23 -04:00
}