libft_old/src/ft_strncmp.c
2024-10-10 18:00:53 +02:00

30 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* ft_strncmp.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/10/10 17:00:31 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/10/10 17:00:31 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
if (n == 0)
return (0);
while (*s1 && *s1 == *s2 && i < n - 1)
{
s1++;
s2++;
i++;
}
return ((unsigned char) *s1 - (unsigned char) *s2);
}