-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strstr.c
executable file
·42 lines (39 loc) · 1.31 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
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tnghondz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/14 14:04:30 by tnghondz #+# #+# */
/* Updated: 2018/05/28 23:20:02 by tnghondz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *haystack, const char *needle)
{
unsigned int npos;
unsigned int hpos;
size_t nlen;
npos = 0;
hpos = 0;
nlen = ft_strlen(needle);
if (nlen == 0)
{
return ((char*)haystack);
}
while (haystack[hpos])
{
npos = 0;
while (needle[npos] == haystack[npos + hpos])
{
if (npos == (nlen - 1))
{
return ((char *)haystack + hpos);
}
npos++;
}
hpos++;
}
return (NULL);
}