You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
1.3 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 19:35:23 by emartine #+# #+# */
/* Updated: 2017/11/07 19:35:26 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *str, const char *to_find, size_t len)
{
size_t i;
size_t j;
if (to_find[0] == '\0')
return ((char *)str);
i = 0;
while (i < len && str[i] != '\0')
{
j = 0;
while (to_find[j] != '\0')
{
if (i + j >= len || str[i + j] != to_find[j])
break ;
j++;
}
if (to_find[j] == '\0')
return ((char *)(str + i));
i++;
}
return (0);
}