-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
39 lines (36 loc) · 1.33 KB
/
ft_strnstr.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_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ewilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 21:47:19 by ewilliam #+# #+# */
/* Updated: 2016/12/08 14:55:59 by ewilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_str_in_strn(const char *s, const char *find, size_t len)
{
if (!*find)
return (1);
if (*s && *find && len)
{
if (*s == *find)
return (is_str_in_strn(++s, ++find, --len));
}
return (0);
}
char *ft_strnstr(const char *big, const char *little, size_t len)
{
if (!*little)
return ((char*)big);
while (*big && len)
{
if (is_str_in_strn(big, little, len))
return ((char*)big);
big++;
len--;
}
return (NULL);
}