-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
29 lines (26 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anpayot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/08 14:45:05 by anpayot #+# #+# */
/* Updated: 2024/10/08 22:08:14 by anpayot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t needle_len;
if (*needle == 0 || haystack == needle)
return ((char *)haystack);
needle_len = ft_strlen(needle);
while (*haystack && needle_len <= len--)
{
if (!(ft_strncmp((char *)haystack, (char *)needle, needle_len)))
return ((char *)haystack);
haystack++;
}
return (NULL);
}