From f861789c3e5e004395c1b7214757d5a83625d845 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Wed, 6 Mar 2024 21:02:09 +0100 Subject: Setup and current progress Forgot to commit earlier... --- ft_strnstr.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ft_strnstr.c (limited to 'ft_strnstr.c') diff --git a/ft_strnstr.c b/ft_strnstr.c new file mode 100644 index 0000000..b91d162 --- /dev/null +++ b/ft_strnstr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser + +char *ft_strnstr(const char *haystack, const char *needle, size_t len) +{ + size_t i; + size_t k; + + i = 0; + while (i < len) + { + k = 0; + while (haystack[i + k] == needle[k]) + { + k++; + } + if (!needle[k]) + return ((char *)haystack + i); + i++; + } + return (0); +} + +/* #include */ +/* int main() { */ +/* char haystack[] = "Hello world"; */ +/* char needle[] = "d"; */ +/* printf("strnstr: %s\n", strnstr(haystack, needle, 10)); */ +/* printf("ft_strnstr: %s\n", ft_strnstr(haystack, needle, 10)); */ +/* } */ -- cgit v1.2.3