-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
34 lines (31 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgiraldo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/29 17:08:15 by mgiraldo #+# #+# */
/* Updated: 2020/03/05 14:54:55 by mgiraldo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *haystack, const char *needle)
{
char *nptr;
unsigned int nlen;
nlen = ft_strlen(needle);
if (!(needle && *needle))
return ((char *)haystack);
while (*haystack)
{
if (!(nptr = ft_strchr(haystack, *(needle + nlen - 1))))
return (NULL);
haystack = nptr - nlen + 1;
if (*haystack == *needle)
if (!ft_strncmp(haystack, needle, nlen - 1))
return ((char *)haystack);
haystack = nptr + 1;
}
return (NULL);
}