Piscine-C03/ex01/ft_strncmp.c

45 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/14 02:38:17 by lfirmin #+# #+# */
/* Updated: 2024/02/14 03:58:48 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
unsigned int r;
unsigned int c;
c = 0;
r = 0;
while ((s1[c] != '\0' || s2[c] != '\0') && c < n)
{
if (s1[c] != s2[c])
{
r = s1[c] - s2[c];
break ;
}
c++;
}
return (r);
}
/*#include <stdio.h>
int main()
{
char *s1 = "hellohelf";
char *s2 = "hellohel";
unsigned int n = 9;
int result = ft_strncmp(s1, s2, n);
printf("%d\n", result);
return 0;
}*/