-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
executable file
·30 lines (27 loc) · 1.14 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <jraymond@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/15 17:12:39 by jraymond #+# #+# */
/* Updated: 2017/11/15 17:12:42 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s1, const char *s2, size_t n)
{
size_t len;
if (!*s2)
return ((char *)s1);
len = ft_strlen(s2);
while (*s1 && n >= len)
{
if (!ft_strncmp(s1, s2, len))
return ((char *)s1);
n--;
s1++;
}
return (NULL);
}