-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strstr.c
50 lines (43 loc) · 1.37 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
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jony <jony@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/21 15:19:09 by mhasan #+# #+# */
/* Updated: 2019/11/04 22:11:34 by jony ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(char *str, const char *to_find)
{
unsigned int i;
unsigned int j;
if (to_find[0] == '\0')
return (str);
i = 0;
while (str[i] != '\0')
{
j = 0;
while (str[i + j] == to_find[j])
{
if (to_find[j + 1] == '\0')
{
return (str + i);
}
j++;
}
i++;
}
return (0);
}
int main()
{
char haystack[20] = "TutorialsPoint";
char needle[10] = "Point";
char *ret;
ret = ft_strstr(haystack, needle);
printf("The substring is: %s\n", ret);
return (0);
}