-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path04_ft_strstr.c
50 lines (44 loc) · 1.42 KB
/
04_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 04_ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anajmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/05 15:24:29 by anajmi #+# #+# */
/* Updated: 2021/07/07 16:42:44 by anajmi ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <string.h>
char *ft_strcpy(char *dest, char *src);
char *ft_strstr(char *str, char *to_find)
{
unsigned int i;
unsigned int j;
if (*to_find == '\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(void)
{
char str[50];
char to_find[50];
ft_strcpy(str, "ghost every ");
ft_strcpy(to_find, "os");
puts(ft_strstr(str, to_find));
puts(strstr(str, to_find));
return (0);
}