diff options
Diffstat (limited to 'ft_strstr.c')
| -rw-r--r-- | ft_strstr.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/ft_strstr.c b/ft_strstr.c index f71423f..4d4d403 100644 --- a/ft_strstr.c +++ b/ft_strstr.c @@ -6,34 +6,24 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:15:29 by cacharle #+# #+# */ -/* Updated: 2019/10/07 10:21:49 by cacharle ### ########.fr */ +/* Updated: 2019/11/20 03:58:32 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -#include <stdlib.h> -#include <string.h> #include "libft.h" char *ft_strstr(const char *haystack, const char *needle) { - size_t i; - char *cursor; + size_t needle_len; - cursor = (char*)haystack; - if (!ft_strlen(needle)) - return (cursor); - while (*cursor) + needle_len = ft_strlen(needle); + if (needle_len == 0) + return ((char*)haystack); + while (*haystack) { - i = 0; - while (needle[i] && cursor[i]) - { - if (needle[i] != cursor[i]) - break ; - i++; - } - if (i == ft_strlen(needle)) - return (cursor); - cursor++; + if (ft_strnequ(haystack, needle, needle_len)) + return ((char*)haystack); + haystack++; } return (NULL); } |
