-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
32 lines (29 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lenzo-pe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/10 17:06:57 by lenzo-pe #+# #+# */
/* Updated: 2021/04/06 22:36:33 by lenzo-pe ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
char *ft_strnstr(const char *str, const char *substr, size_t len)
{
size_t sub_len;
size_t i;
i = 0;
sub_len = ft_strlen(substr);
if (!sub_len)
return ((char *)str);
while (str[i] && sub_len <= len)
{
if (ft_strncmp(&str[i], substr, sub_len) == 0)
return ((char *)&str[i]);
i++;
len--;
}
return (NULL);
}