diff --git a/ex04/ft_strstr.c b/ex04/ft_strstr.c index e8ce8e1..4b9fa68 100644 --- a/ex04/ft_strstr.c +++ b/ex04/ft_strstr.c @@ -6,33 +6,56 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/24 02:23:28 by tischmid #+# #+# */ -/* Updated: 2023/03/28 20:03:53 by tischmid ### ########.fr */ +/* Updated: 2023/03/29 00:17:36 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ +int strstr_cmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + ++s1; + ++s2; + } + return (!*s2); +} + char *ft_strstr(char *str, char *to_find) { - int offset; - char *orig_to_find; - - orig_to_find = to_find; + if (!*to_find) + return (str); while (*str) { - offset = 0; - while (to_find[offset]) - { - if (!str[offset] && to_find[offset] != str[offset]) - break ; - ++offset; - } - if (!to_find[offset]) + if (strstr_cmp(str, to_find)) return (str); - to_find = orig_to_find; ++str; } - return (0); + return ((void *) 0); } +// char *ft_strstr(char *str, char *to_find) +// { +// int offset; +// char *orig_to_find; +// +// orig_to_find = to_find; +// while (*str) +// { +// offset = 0; +// while (to_find[offset]) +// { +// if (!str[offset] && to_find[offset] != str[offset]) +// break ; +// ++offset; +// } +// if (!to_find[offset]) +// return (str); +// to_find = orig_to_find; +// ++str; +// } +// return (0); +// } + /* //// #include