-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathft_strstr.c
42 lines (39 loc) · 1.43 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: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/04 14:36:51 by apuchill #+# #+# */
/* Updated: 2020/10/30 19:58:10 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: locate a substring in a string
**
** DESCRIPTION:
** The strstr() function locates the first occurrence of the null-
** terminated string s2 in the null-terminated string s1.
*/
char *ft_strstr(const char *haystack, const char *needle)
{
int i;
int j;
i = 0;
if (needle[0] == '\0')
return ((char *)haystack);
while (haystack[i] != '\0')
{
j = 0;
while (haystack[i + j] == needle[j] && haystack[i + j] != '\0')
{
if (needle[j + 1] == '\0')
return ((char *)&haystack[i]);
j++;
}
i++;
}
return (0);
}