-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
executable file
·35 lines (32 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbensado <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/23 15:02:57 by kbensado #+# #+# */
/* Updated: 2015/12/31 13:24:12 by kbensado ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s1, const char *s2, size_t n)
{
size_t i;
if (!(*s2))
return ((char *)s1);
while (*s1 && n--)
{
if (*s1 == s2[0])
{
i = 1;
while (n-- && s1[i] && s2[i] && s1[i] == s2[i])
++i;
if (i == ft_strlen(s2))
return ((char *)s1);
n += i;
}
s1++;
}
return (NULL);
}