-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strnstr.c
29 lines (26 loc) · 1.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abello-r <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/10 15:05:09 by abello-r #+# #+# */
/* Updated: 2020/01/26 12:11:28 by abello-r ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *h, const char *needle, size_t len)
{
size_t c;
if (*needle == 0 || h == needle)
return ((char *)h);
c = ft_strlen(needle);
while (*h && c <= len--)
{
if (!(ft_strncmp((char *)h, (char *)needle, c)))
return ((char *)h);
h++;
}
return (NULL);
}