Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_strnstr.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_strnstr.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: raphalme <raphalme@student.42.fr> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2025/12/29 18:53:00 by raphalme #+# #+# */
9
/* Updated: 2026/04/14 10:45:22 by raphalme ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include <stdlib.h>
14
25
char
*
ft_strnstr
(
const
char
*haystack,
const
char
*needle,
size_t
len)
26
{
27
size_t
i;
28
size_t
j;
29
30
if
(!*needle)
31
return
((
char
*)haystack);
32
i = 0;
33
while
(haystack[i] && i < len)
34
{
35
j = 0;
36
while
(haystack[i + j] && needle[j] && i + j < len
37
&& haystack[i + j] == needle[j])
38
j++;
39
if
(!needle[j])
40
return
((
char
*)&haystack[i]);
41
i++;
42
}
43
return
(NULL);
44
}
ft_strnstr
char * ft_strnstr(const char *haystack, const char *needle, size_t len)
Finds a substring within a bounded string region.
Definition
ft_strnstr.c:25
src
ft_strnstr.c
Generated by
1.9.8