-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strstr.c
33 lines (30 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mesafi <mesafi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/02 00:35:19 by mesafi #+# #+# */
/* Updated: 2019/11/13 22:35:23 by mesafi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *str, const char *needle)
{
char *pkey;
size_t nlen;
nlen = ft_strlen(needle);
if (!(*needle))
return ((char *)str);
while (*str)
{
pkey = ft_memchr(str, *needle, ft_strlen(str));
if (!(pkey))
return (0);
if (ft_memcmp(needle, pkey, nlen) == 0)
return (pkey);
str = pkey + 1;
}
return (0);
}