libft
ft_strstr.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ft_strstr.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/04 23:39:32 by unite #+# #+# */
10 /* Updated: 2020/07/16 02:43:51 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "libft.h"
15 
20 char *ft_strstr(const char *haystack, const char *needle)
21 {
22  size_t i;
23  size_t j;
24 
25  i = 0;
26  if (*needle == 0)
27  return ((char *)haystack);
28  while (haystack[i])
29  {
30  if (haystack[i] == needle[0])
31  {
32  j = 0;
33  while (needle[j] && haystack[i + j] == needle[j])
34  j++;
35  if (needle[j] == 0)
36  return ((char *)(haystack + i));
37  }
38  i++;
39  }
40  return (NULL);
41 }
libft.h
ft_strstr
char * ft_strstr(const char *haystack, const char *needle)
Replicates behaviour of strstr from libc.
Definition: ft_strstr.c:20