From b590433a12d55a28a954e4020b4d13142c78843b Mon Sep 17 00:00:00 2001 From: Timo Schmidt Date: Fri, 24 Mar 2023 02:21:09 +0100 Subject: [PATCH] ex01 --- ex01/ft_strncmp.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ex01/ft_strncmp.c diff --git a/ex01/ft_strncmp.c b/ex01/ft_strncmp.c new file mode 100644 index 0000000..1f11fde --- /dev/null +++ b/ex01/ft_strncmp.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tischmid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#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); +} +*/ ////