-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strstr.c
More file actions
42 lines (39 loc) · 1.27 KB
/
Copy pathft_strstr.c
File metadata and controls
42 lines (39 loc) · 1.27 KB
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: gdannay <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/09 19:54:44 by gdannay #+# #+# */
/* Updated: 2018/01/08 14:53:50 by gdannay ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
char *ft_strstr(const char *str, const char *need)
{
int i;
int j;
int k;
i = 0;
j = 0;
k = 0;
if (str == NULL || need == NULL)
return (NULL);
while (str[i] != '\0')
{
while (str[i + k] == need[j])
{
k++;
j++;
if (need[j] == '\0')
return ((char *)(str + i));
}
k = 0;
j = 0;
i++;
}
if (need[j] == '\0')
return ((char *)(str));
return (NULL);
}