-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
27 lines (24 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: laime <laime@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/04 17:49:30 by laime #+# #+# */
/* Updated: 2014/11/23 12:52:31 by laime ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
char *ft_strnstr(const char *s1, const char *s2, size_t n)
{
size_t len_s2;
len_s2 = ft_strlen(s2);
if (!*s2)
return ((char*)s1);
while (*s1 && len_s2 <= n--)
if (!ft_memcmp(s1++, s2, len_s2))
return ((char*)s1 - 1);
return (NULL);
}