-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
29 lines (26 loc) · 1.26 KB
/
ft_strnstr.c
File metadata and controls
29 lines (26 loc) · 1.26 KB
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: fgalan-n <fgalan-n@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/25 13:55:14 by fgalan-n #+# #+# */
/* Updated: 2022/09/25 14:21:13 by fgalan-n ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t len_needle;
len_needle = ft_strlen(needle);
if (*needle == 0 || haystack == needle)
return ((char *)haystack);
while (*haystack && len_needle <= len--)
{
if (!(ft_strncmp((char *)haystack, (char *)needle, len_needle)))
return ((char *)haystack);
haystack++;
}
return (NULL);
}