From bbdc932411501e239757985023942f93d1b21f46 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 12 Oct 2019 13:54:35 +0200 Subject: Fixed ft_strlcat and ft_strnstr to pass Libftest tests --- ft_strnstr.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'ft_strnstr.c') diff --git a/ft_strnstr.c b/ft_strnstr.c index d65a6f6..ebe2fcf 100644 --- a/ft_strnstr.c +++ b/ft_strnstr.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:25:13 by cacharle #+# #+# */ -/* Updated: 2019/10/07 12:40:59 by cacharle ### ########.fr */ +/* Updated: 2019/10/12 13:51:56 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,10 +21,14 @@ char *ft_strnstr(const char *haystack, const char *needle, size_t len) size_t needle_len; needle_len = ft_strlen(needle); - if (needle_len == 0 || len == 0) + if (needle_len == 0 && len == 0) return ((char*)haystack); - i = 0; - while (i < len && haystack[i]) + if (len == 0) + return (NULL); + if (needle_len == 0) + return ((char*)haystack); + i = -1; + while (++i < len && haystack[i]) { j = 0; while (i + j < len && needle[j] && haystack[i + j]) @@ -35,7 +39,6 @@ char *ft_strnstr(const char *haystack, const char *needle, size_t len) } if (j == needle_len) return ((char*)haystack + i); - i++; } return (NULL); } -- cgit