-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
30 lines (27 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aabda <aabda@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/07 15:00:14 by aabda #+# #+# */
/* Updated: 2022/07/18 15:38:04 by aabda ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t size;
if (*needle == '\0')
return ((char *)haystack);
size = ft_strlen(needle);
while (*haystack != '\0' && len >= size)
{
if (*haystack == *needle && ft_strncmp(haystack, needle, size) == 0)
return ((char *)haystack);
haystack++;
len--;
}
return (NULL);
}