-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_strnstr.c
38 lines (34 loc) · 1.26 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
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: psprawka <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/06/17 12:27:29 by psprawka #+# #+# */
/* Updated: 2018/06/17 13:43:33 by psprawka ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(char *str, char *to_find, size_t len)
{
size_t i;
unsigned x;
i = 0;
if (!to_find)
return (str);
while (str[i] && (i < len))
{
x = 0;
while (str[i] && str[i] == to_find[x] && i < len)
{
x++;
i++;
}
if (to_find[x])
return ((char *)&str[i - x]);
i = i - x + 1;
}
return (NULL);
//look here something is ugly and may not work
}