-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
32 lines (29 loc) · 1.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bcaffere <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/24 20:02:30 by bcaffere #+# #+# */
/* Updated: 2021/04/24 21:57:11 by bcaffere ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s, const char *find, size_t n)
{
char *str;
size_t i;
str = (char *)s;
i = ft_strlen(find);
if (i == 0)
return (str);
while (*str && n > 0 && n >= i)
{
if (ft_strncmp(str, find, i) == 0)
return (str);
str++;
n--;
}
return (NULL);
}