tgrekov-libft
HIVE libft Oct 2023
Loading...
Searching...
No Matches
ft_strnstr.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_strnstr.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2023/10/25 12:42:03 by tgrekov #+# #+# */
9
/* Updated: 2023/11/09 20:05:15 by tgrekov ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
20
#include "
libft.h
"
21
33
char
*
ft_strnstr
(
const
char
*haystack,
const
char
*needle,
size_t
len)
34
{
35
size_t
hix;
36
size_t
nix;
37
38
if
(!needle[0])
39
return
((
char
*) haystack);
40
hix = 0;
41
while
(hix < len && haystack[hix])
42
{
43
nix = 0;
44
while
(hix + nix < len && needle[nix] && haystack[hix + nix]
45
&& needle[nix] == haystack[hix + nix])
46
nix++;
47
if
(!needle[nix])
48
return
((
char
*) haystack + hix);
49
hix++;
50
}
51
return
(0);
52
}
ft_strnstr
char * ft_strnstr(const char *haystack, const char *needle, size_t len)
Finds first occurence of needle in string haystack.
Definition
ft_strnstr.c:33
libft.h
ft_strnstr.c