-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
39 lines (37 loc) · 1.23 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
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybouzgao <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 15:35:20 by ybouzgao #+# #+# */
/* Updated: 2017/11/13 18:28:50 by ybouzgao ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strstr(const char *haystack, const char *needle)
{
int i;
int j;
i = 0;
while (needle[i])
i++;
if (i < 1)
return ((char *)haystack);
else
{
i = 0;
while (haystack[i])
{
j = 0;
while (needle[j] == haystack[i + j])
{
if (needle[j + 1] == '\0')
return ((char *)(haystack + i));
j++;
}
i++;
}
return (0);
}
}