libft/ft_strstr.c
2018-04-05 11:24:30 +02:00

33 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/05 10:54:41 by tmaze #+# #+# */
/* Updated: 2018/04/05 11:19:02 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *haystack, const char *needle)
{
int i;
int j;
char *tmp;
i = -1;
tmp = (char*)haystack;
while (++i == 0 || tmp[i - 1])
if (tmp[i] == needle[0] && (j = 1))
{
while (tmp[i + j] == needle[j] && needle[j] && tmp[i + j])
j++;
if (needle[j] == '\0')
return (&tmp[i]);
}
return (NULL);
}