-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
45 lines (42 loc) · 1.36 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
43
44
45
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sadamant <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/21 13:28:25 by sadamant #+# #+# */
/* Updated: 2017/09/21 16:31:26 by sadamant ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int check_substring(const char *haystack, const char *needle)
{
while (*needle)
{
if (*haystack++ == *needle++)
;
else
return (-1);
}
return (1);
}
char *ft_strstr(const char *haystack, const char *needle)
{
if (ft_strcmp(needle, "") == 0)
{
return ((char *)haystack);
}
while (*haystack)
{
if (*haystack == *needle)
{
if (check_substring(haystack, needle) > 0)
{
return ((char *)haystack);
}
}
haystack++;
}
return (NULL);
}