This commit is contained in:
Timo Schmidt 2023-03-24 02:21:09 +01:00
parent 542478f968
commit b590433a12
1 changed files with 41 additions and 0 deletions

41
ex01/ft_strncmp.c Normal file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/24 02:01:33 by tischmid #+# #+# */
/* Updated: 2023/03/24 02:04:30 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
while (*s1 && *s2 && *s1 == *s2 && --n)
{
++s1;
++s2;
}
return (*s1 - *s2);
}
/* ////
#include <stdio.h>
#define STR1 "abd"
#define STR2 "abc"
#define LENGTH 3
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);
}
*/ ////