-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
48 lines (44 loc) · 1.39 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
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rakama <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/05 18:03:01 by rakama #+# #+# */
/* Updated: 2022/05/13 14:29:10 by rakama ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_result(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (i < len)
{
if (big[i] == little[j])
{
i++;
j++;
if (little[j] == '\0')
return ((char *)&big[i - j]);
}
else
{
i -= j;
i++;
j = 0;
}
if (big[i] == '\0' || little[j] == '\0')
break ;
}
return (NULL);
}
char *ft_strnstr(const char *big, const char *little, size_t len)
{
if (little[0] == '\0')
return ((char *)big);
return (ft_result(big, little, len));
}