-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
27 lines (25 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmita <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/17 16:08:42 by mmita #+# #+# */
/* Updated: 2022/11/17 16:59:53 by mmita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
if (!*needle)
return ((char *)haystack);
while (*haystack && len-- >= ft_strlen(needle))
{
if (ft_memcmp(haystack, needle, ft_strlen(needle)) == 0)
return ((char *)haystack);
haystack++;
}
return (NULL);
}