-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strstr.c
31 lines (28 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aelphias <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 16:37:10 by aelphias #+# #+# */
/* Updated: 2019/09/28 15:28:22 by aelphias ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *haystack, const char *needle)
{
int size_m;
int i;
int size_b;
i = 0;
if (needle[0] == '\0')
return ((char *)haystack);
size_m = ft_strlen(needle);
size_b = ft_strlen(haystack);
while (ft_strncmp(&haystack[i], needle, size_m) && (i <= (size_b - size_m)))
i++;
if ((i <= (size_b - size_m)))
return ((char *)&haystack[i]);
return (NULL);
}