-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
35 lines (32 loc) · 1.25 KB
/
ft_strstr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tlevaufr <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/13 16:51:53 by tlevaufr #+# #+# */
/* Updated: 2017/12/29 19:22:34 by tlevaufr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *str, const char *to_find)
{
size_t i;
size_t j;
size_t needle_size;
i = 0;
needle_size = ft_strlen((char*)to_find);
if (!(*to_find))
return ((char *)str);
while (str[i])
{
j = 0;
while (str[i + j] && to_find[j] && to_find[j] == str[i + j])
j++;
if (j == needle_size)
return ((char *)&str[i]);
i++;
}
return (NULL);
}