-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strstr.c
41 lines (38 loc) · 1.32 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
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nhennigh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/11 18:57:41 by nhennigh #+# #+# */
/* Updated: 2019/02/14 16:29:39 by nhennigh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *haystack, const char *needle)
{
int i;
int j;
int k;
int good;
if (!ft_strlen(needle))
return ((char *)haystack);
i = -1;
good = 0;
while (*(haystack + ++i) && !good)
{
if (*(haystack + i) == *needle)
{
j = 0;
k = i;
good = 1;
while (*(needle + j))
if (*(needle + j++) != *(haystack + k++))
good = 0;
if (good)
return ((char *)(haystack + i));
}
}
return (NULL);
}