-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
42 lines (39 loc) · 1.32 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
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <earnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/05 17:21:09 by earnaud #+# #+# */
/* Updated: 2020/11/09 15:37:06 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
size_t little_len;
i = 0;
little_len = ft_strlen(little);
if (!*little)
return ((char *)big);
while (i <= len && big[i])
{
j = 0;
while (j <= little_len && i + j < len)
{
if (little[j] == big[i + j])
{
if (j == little_len - 1)
return ((char *)(big + i));
j++;
}
else
break ;
}
i++;
}
return (0);
}