piscine-c03/ex04/ft_strstr.c

51 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/24 02:23:28 by tischmid #+# #+# */
/* Updated: 2023/03/24 03:18:35 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
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 (*(to_find + offset) != *(str + offset))
break ;
++offset;
}
if (!*(to_find + offset))
return (str);
to_find = orig_to_find;
++str;
}
return ((void *) 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));
return (0);
}
*/ ////