-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_strnstr.c
35 lines (32 loc) · 1.31 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
31
32
33
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlambert <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/04 14:58:25 by rlambert #+# #+# */
/* Updated: 2015/11/09 19:24:46 by roblabla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strnstr(const char *haystack, const char *needle, size_t hlen)
{
size_t nlen;
int lastresult;
if (*needle == '\0')
return ((char*)haystack);
nlen = ft_strlen(needle);
lastresult = 1;
while (nlen <= hlen && *haystack != '\0'
&& (lastresult = ft_strncmp(haystack, needle, nlen)))
{
hlen--;
haystack++;
}
if (lastresult != 0)
return (NULL);
else
return ((char *)haystack);
}