-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
31 lines (28 loc) · 1.25 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/26 11:10:30 by yochered #+# #+# */
/* Updated: 2018/10/26 11:10:32 by yochered ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
char *str;
size_t substr_len;
substr_len = ft_strlen(needle);
str = (char *)haystack;
if (substr_len == 0)
return (str);
while (*str && len-- >= substr_len)
{
if (ft_memcmp(str, needle, substr_len) == 0)
return (str);
str++;
}
return (NULL);
}