aboutsummaryrefslogtreecommitdiff
path: root/ft_strnstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'ft_strnstr.c')
-rw-r--r--ft_strnstr.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/ft_strnstr.c b/ft_strnstr.c
index 5f6f0f1..4ca9f4b 100644
--- a/ft_strnstr.c
+++ b/ft_strnstr.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:25:13 by cacharle #+# #+# */
-/* Updated: 2019/10/20 14:21:42 by cacharle ### ########.fr */
+/* Updated: 2019/10/21 11:04:56 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,20 +16,16 @@
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
- size_t i;
- /* size_t j; */
size_t needle_len;
- char *mut_haystack;
needle_len = ft_strlen(needle);
if (needle_len == 0)
return ((char*)haystack);
- mut_haystack = (char*)haystack;
- i = -1;
- while (++i < len && haystack[i])
+ while (*haystack && len-- >= needle_len)
{
- if (ft_strncmp(mut_haystack + i, needle, needle_len) == 0)
- return (mut_haystack + i);
+ if (ft_strncmp(haystack, needle, needle_len) == 0)
+ return ((char*)haystack);
+ haystack++;
}
return (NULL);
}