piscine-c03/ex01/ft_strncmp.c

44 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/24 02:01:33 by tischmid #+# #+# */
/* Updated: 2023/03/28 18:55:41 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
if (!n)
return (1);
while (*s1 && *s2 && *s1 == *s2 && --n)
{
++s1;
++s2;
}
return (*s1 - *s2);
}
/* ////
#include <stdio.h>
#define STR1 "abd"
#define STR2 "abc"
#define LENGTH 0
int main(void)
{
int result;
printf("'%s' VS '%s' length %d\n", STR1, STR2, LENGTH);
result = ft_strncmp(STR1, STR2, LENGTH);
if(!result)
printf("Strings are the same (0)\n");
else
printf("Strings are different (offset=%d)\n", result);
return (0);
}
*/ ////