-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
executable file
·47 lines (43 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/12 17:21:35 by mwilliam #+# #+# */
/* Updated: 2016/12/09 12:33:53 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Locates the first occurence of the string "little" in the string "big"
** but searches no more than len characters
*/
char *ft_strnstr(const char *big, const char *little, size_t len)
{
const char *big2;
const char *little2;
size_t n;
if (*little == '\0')
return ((char *)big);
while (*big && len > 0)
{
if (*big == *little)
{
big2 = big;
little2 = little;
n = len;
while (n-- && *big2 && *little2 && *big2 == *little2)
{
big2++;
little2++;
}
if (*little2 == '\0')
return ((char *)big);
}
big++;
len--;
}
return (NULL);
}