diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-11-20 04:04:55 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-11-20 04:04:55 +0100 |
| commit | 9901cd05849fa0ef396f09f57b07807ebd96ca32 (patch) | |
| tree | f2dd9c191512bfc11c994e578291cccf270de787 /ft_strstr.c | |
| parent | a983b06df18647cf63fadad5b36f472e06f1075f (diff) | |
| download | libft-9901cd05849fa0ef396f09f57b07807ebd96ca32.tar.gz libft-9901cd05849fa0ef396f09f57b07807ebd96ca32.tar.bz2 libft-9901cd05849fa0ef396f09f57b07807ebd96ca32.zip | |
refactored everything
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); } |
