-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
36 lines (33 loc) · 1.36 KB
/
Copy pathft_strnstr.c
File metadata and controls
36 lines (33 loc) · 1.36 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
30
31
32
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmelvin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/08 12:40:21 by tmelvin #+# #+# */
/* Updated: 2019/10/27 15:53:44 by tmelvin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
int i;
size_t needle_len;
i = 0;
if (haystack == NULL || needle == NULL)
return (NULL);
needle_len = ft_strlen(needle);
if (needle_len == 0)
return ((char *)haystack);
if (len == 0)
return (NULL);
while (i++ <= (int)(len - needle_len))
{
if (*haystack == *needle &&
(0 == ft_strncmp(haystack, needle, needle_len)))
return ((char *)haystack);
haystack++;
}
return (NULL);
}