-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
37 lines (34 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: malexand <malexand@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 13:19:39 by malexand #+# #+# */
/* Updated: 2017/02/16 17:34:27 by malexand ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t n)
{
int count_big;
int count_little;
count_big = 0;
count_little = 0;
while (big[count_big] != '\0' && count_big < (int)n)
{
if (big[count_big] == little[0])
while (big[count_big + count_little] == little[count_little]
&& little[count_little] != '\0'
&& big[count_big + count_little] != '\0'
&& count_big + count_little < (int)n)
count_little++;
if (count_little == (int)ft_strlen(little))
return ((char *)big + count_big);
else if (count_little != 0)
count_little = 0;
count_big++;
}
return (NULL);
}