-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strstr.c
46 lines (41 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alaulom <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/07 14:15:44 by alaulom #+# #+# */
/* Updated: 2014/11/12 13:41:56 by alaulom ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int scan(char *str, const char *to_find)
{
int i;
i = 0;
while (to_find[i])
{
if (str[i] != to_find[i])
return (0);
i++;
}
return (1);
}
char *ft_strstr(const char *str, const char *to_find)
{
int i;
char *ptrstr;
ptrstr = (char *)str;
if (!*to_find)
return (ptrstr);
i = 0;
while (ptrstr[i])
{
if (ptrstr[i] == to_find[0])
if (scan(&ptrstr[i], to_find))
return (&ptrstr[i]);
i++;
}
return (NULL);
}