-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
40 lines (37 loc) · 1.3 KB
/
ft_strnstr.c
File metadata and controls
40 lines (37 loc) · 1.3 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
30
31
32
33
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ibohonos <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/25 18:07:01 by ibohonos #+# #+# */
/* Updated: 2017/10/25 18:07:03 by ibohonos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *str1, const char *str2, size_t len)
{
size_t i;
size_t z;
int l;
if (*str2 == '\0')
return ((char *)str1);
i = 0;
while (i < len && *str1 != '\0')
{
l = 0;
z = i;
while (z < len && *(str1 + l) == *(str2 + l))
{
if (*(str2 + l + 1) == '\0')
return ((char *)str1);
else if (*(str1 + l++) == '\0')
return (NULL);
z++;
}
str1++;
i++;
}
return (NULL);
}