-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
42 lines (39 loc) · 1.28 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: vvenance <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/24 15:26:35 by vvenance #+# #+# */
/* Updated: 2015/12/14 15:53:34 by vvenance ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *s1, const char *s2)
{
int i;
int j;
int mark;
i = 0;
if (!s2 || s2[i] == '\0')
return (char *)(s1);
while (s1[i])
{
j = 0;
mark = -1;
if (s1[i] == s2[j])
mark = i;
while (s1[i] == s2[j] && s2[j] != '\0')
{
if (s2[j + 1] == '\0')
return (char *)&s1[mark];
i++;
j++;
}
if (mark != -1)
i = mark;
i++;
}
return (NULL);
}