aboutsummaryrefslogtreecommitdiff
path: root/ft_strstr.c
blob: 0209de4ef44977b24d43298e554667131e46baba (plain)
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
#include <stdlib.h>
#include <string.h>
#include "libft.h"

char *ft_strstr(const char *haystack, const char *needle)
{
	size_t  i;
    char    *cursor;

    cursor = (char*)haystack;
	if (!ft_strlen(needle))
		return (cursor);
	while (*cursor)
	{
		i = 0;
		while (needle[i] && cursor[i])
		{
			if (needle[i] != cursor[i])
				break ;
			i++;
		}
		if (i == ft_strlen(needle))
			return (cursor);
		cursor++;
	}
	return (NULL);
}