libft
src
ft_strnstr.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* ft_strnstr.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2019/09/04 23:47:47 by unite #+# #+# */
10
/* Updated: 2020/07/16 02:42:54 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
libft.h
"
15
20
char
*
ft_strnstr
(
const
char
*haystack,
const
char
*needle,
size_t
len)
21
{
22
size_t
i;
23
size_t
j;
24
25
i = 0;
26
if
(*needle ==
'\0'
)
27
return
((
char
*)haystack);
28
while
(haystack[i] && i < len)
29
{
30
if
(haystack[i] == needle[0])
31
{
32
j = 0;
33
while
(needle[j] &&
34
i + j < len &&
35
haystack[i + j] == needle[j])
36
j++;
37
if
(needle[j] == 0)
38
return
((
char
*)(haystack + i));
39
}
40
i++;
41
}
42
return
(NULL);
43
}
libft.h
ft_strnstr
char * ft_strnstr(const char *haystack, const char *needle, size_t len)
Replicates behaviour of strnstr from libc.
Definition:
ft_strnstr.c:20
Generated by
1.8.16