diff options
Diffstat (limited to 'ft_strnstr.c')
| -rw-r--r-- | ft_strnstr.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/ft_strnstr.c b/ft_strnstr.c index 0dc21d2..5f6f0f1 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/18 14:26:28 by cacharle ### ########.fr */ +/* Updated: 2019/10/20 14:21:42 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,24 +17,19 @@ char *ft_strnstr(const char *haystack, const char *needle, size_t len) { size_t i; - size_t j; + /* 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]) { - j = 0; - while (i + j < len && needle[j] && haystack[i + j]) - { - if (needle[j] != haystack[i + j]) - break ; - j++; - } - if (j == needle_len) - return ((char*)haystack + i); + if (ft_strncmp(mut_haystack + i, needle, needle_len) == 0) + return (mut_haystack + i); } return (NULL); } |
