-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
42 lines (39 loc) · 1.39 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
36
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chrhuang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/07 13:45:17 by chrhuang #+# #+# */
/* Updated: 2018/11/12 13:49:21 by chrhuang ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *str, const char *find)
{
char *tmp;
char *tmp1;
if (ft_strcmp(find, "") == 0)
return ((char *)str);
while (*str != '\0')
{
if (*str == *find)
{
tmp = (char *)str;
tmp1 = (char *)find;
while (*tmp != '\0')
{
if ((*tmp != *tmp1 && *tmp1 == '\0') ||
(*(tmp + 1) == '\0' && *(tmp1 + 1) == '\0'))
return ((char *)str);
else if (*tmp != *tmp1)
break ;
tmp = tmp + 1;
tmp1 = tmp1 + 1;
}
}
str = str + 1;
}
return (NULL);
}