37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strstr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tchivert <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/04/04 20:13:33 by tchivert #+# #+# */
|
|
/* Updated: 2019/09/04 05:13:34 by tchivert ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strstr(const char *haystack, const char *needle)
|
|
{
|
|
int i;
|
|
int j;
|
|
|
|
i = 0;
|
|
if (!*needle)
|
|
return ((char *)haystack);
|
|
while (haystack[i])
|
|
{
|
|
if (haystack[i] == needle[0])
|
|
{
|
|
j = 1;
|
|
while (needle[j] && haystack[i + j] == needle[j])
|
|
j++;
|
|
if (needle[j] == '\0')
|
|
return ((char *)haystack + i);
|
|
}
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|