-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
31 lines (28 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
31
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yeonhkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/23 00:09:32 by yeonhkim #+# #+# */
/* Updated: 2022/07/23 02:17:17 by yeonhkim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t i;
size_t n_len;
n_len = ft_strlen(needle);
if (!needle || *needle == '\0')
return ((char *)haystack);
i = 0;
while (haystack[i] && (i + n_len) <= len)
{
if (ft_strncmp(&haystack[i], needle, n_len) == 0)
return ((char *)(haystack + i));
i++;
}
return (NULL);
}