-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
29 lines (26 loc) · 1.15 KB
/
ft_strnstr.c
File metadata and controls
29 lines (26 loc) · 1.15 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lscariot <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/23 12:13:51 by lscariot #+# #+# */
/* Updated: 2015/11/26 17:39:30 by lscariot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(char *str, char *c, size_t n)
{
size_t len;
if (*c == '\0')
return ((char *)str);
len = ft_strlen(c);
while (*str != '\0' && n-- >= len)
{
if (*str == *c && ft_memcmp(str, c, len) == 0)
return ((char *)str);
str++;
}
return (NULL);
}