-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
38 lines (35 loc) · 1.29 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
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sonyacorcoran <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/21 14:46:02 by sonyacorcor #+# #+# */
/* Updated: 2023/08/21 15:07:50 by sonyacorcor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t needle_len;
size_t i;
needle_len = ft_strlen(needle);
i = 0;
if (needle_len == 0)
{
return ((char *)haystack);
}
while (i < len && haystack[i] != '\0')
{
if (ft_strncmp(&haystack[i], needle, needle_len) == 0)
{
if (i + needle_len <= len)
{
return ((char *)&haystack[i]);
}
}
i++;
}
return (NULL);
}