-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
executable file
·33 lines (30 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
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: toramo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 10:19:24 by toramo #+# #+# */
/* Updated: 2023/10/31 11:34:10 by toramo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *str, const char *to_find, size_t len)
{
size_t l;
size_t i;
i = 0;
l = ft_strlen(to_find);
if (str == 0 && len > 0)
ft_strlen(&str[0]);
if (to_find[0] == 0)
return ((char *)str);
while (i + l <= len && str[i] != 0)
{
if (ft_strncmp(to_find, &str[i], l) == 0)
return ((char *)&str[i]);
i++;
}
return (0);
}