-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
36 lines (33 loc) · 1.29 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
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: moel-asr <moel-asr@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/07 09:30:25 by moel-asr #+# #+# */
/* Updated: 2022/10/19 19:33:50 by moel-asr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *str, const char *to_find, size_t len)
{
size_t i;
size_t j;
i = 0;
j = 0;
if ((!to_find || !str) && len == 0)
return (NULL);
if (to_find[j] == '\0')
return ((char *)str);
while (str[i] != '\0')
{
while (str[i + j] == to_find[j] && str[i + j] != '\0')
j++;
if (to_find[j] == '\0' && (i + j) <= len)
return ((char *)str + i);
i++;
j = 0;
}
return (NULL);
}