This commit is contained in:
Timo Schmidt 2023-03-28 20:04:05 +02:00
parent 744ca0f97a
commit 23f4400768
1 changed files with 29 additions and 10 deletions

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/24 02:23:28 by tischmid #+# #+# */
/* Updated: 2023/03/28 17:42:14 by tischmid ### ########.fr */
/* Updated: 2023/03/28 20:03:53 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,30 +19,49 @@ char *ft_strstr(char *str, char *to_find)
while (*str)
{
offset = 0;
while (*(to_find + offset))
while (to_find[offset])
{
if (*(to_find + offset) != *(str + offset))
if (!str[offset] && to_find[offset] != str[offset])
break ;
++offset;
}
if (!*(to_find + offset))
if (!to_find[offset])
return (str);
to_find = orig_to_find;
++str;
}
return ((void *) 0);
return (0);
}
/* ////
#include <stdio.h>
#define STR1 "hello"
#define STR2 "aa"
int main(void)
{
printf("String to search in: %s\n", STR1);
printf("String to find: %s\n", STR2);
printf("Result: %s\n", ft_strstr(STR1, STR2));
printf("<> vs <> == <%s>\n", ft_strstr("", ""));
printf("<a> vs <> == <%s>\n", ft_strstr("a", ""));
printf("<ab> vs <> == <%s>\n", ft_strstr("ab", ""));
printf("<abc> vs <> == <%s>\n", ft_strstr("abc", ""));
printf("<> vs <a> == <%s>\n", ft_strstr("", "a"));
printf("<a> vs <a> == <%s>\n", ft_strstr("a", "a"));
printf("<ab> vs <a> == <%s>\n", ft_strstr("ab", "a"));
printf("<abc> vs <a> == <%s>\n", ft_strstr("abc", "a"));
printf("<> vs <b> == <%s>\n", ft_strstr("", "b"));
printf("<a> vs <b> == <%s>\n", ft_strstr("a", "b"));
printf("<ab> vs <b> == <%s>\n", ft_strstr("ab", "b"));
printf("<abc> vs <b> == <%s>\n", ft_strstr("abc", "b"));
printf("<> vs <c> == <%s>\n", ft_strstr("", "c"));
printf("<a> vs <c> == <%s>\n", ft_strstr("a", "c"));
printf("<ab> vs <c> == <%s>\n", ft_strstr("ab", "c"));
printf("<abc> vs <c> == <%s>\n", ft_strstr("abc", "c"));
printf("<> vs <ab> == <%s>\n", ft_strstr("", "ab"));
printf("<a> vs <ab> == <%s>\n", ft_strstr("a", "ab"));
printf("<ab> vs <ab> == <%s>\n", ft_strstr("ab", "ab"));
printf("<abc> vs <ab> == <%s>\n", ft_strstr("abc", "ab"));
printf("<> vs <abc> == <%s>\n", ft_strstr("", "abc"));
printf("<a> vs <abc> == <%s>\n", ft_strstr("a", "abc"));
printf("<ab> vs <abc> == <%s>\n", ft_strstr("ab", "abc"));
printf("<abc> vs <abc> == <%s>\n", ft_strstr("abc", "abc"));
return (0);
}
*/ ////