-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
38 lines (35 loc) · 1.3 KB
/
ft_strstr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwasserf <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/23 14:41:06 by gwasserf #+# #+# */
/* Updated: 2019/06/24 14:27:23 by ayano ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *haystack, const char *needle)
{
int len;
int index;
index = 0;
len = ft_strlen(needle);
if (len == 0 || (haystack == needle))
return ((char *)haystack);
while (*haystack)
{
while (needle[index] != 0)
{
if (needle[index] != *(haystack + index))
break ;
if (index == len - 1)
return ((char *)haystack);
index++;
}
haystack++;
index = 0;
}
return (NULL);
}