aboutsummaryrefslogtreecommitdiff
path: root/ft_strstr.c
blob: f71423f339f492efaff81d18a2fd8cf8aaa936c6 (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
28
29
30
31
32
33
34
35
36
37
38
39
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_strstr.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/10/07 10:15:29 by cacharle          #+#    #+#             */
/*   Updated: 2019/10/07 10:21:49 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#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);
}