-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
28 lines (25 loc) · 1.11 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cprune <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 14:21:09 by cprune #+# #+# */
/* Updated: 2015/12/06 10:34:25 by cprune ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s1, const char *s2, size_t n)
{
size_t s2len;
s2len = ft_strlen(s2);
while (*s1 && n > 0)
{
if (!ft_memcmp(s1, s2, s2len) && s2len <= n)
return (char *)s1;
n--;
s1++;
}
return (0);
}