/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strnstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/26 12:21:03 by bchanot #+# #+# */ /* Updated: 2018/10/29 11:56:09 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" char *ft_strnstr(const char *const s1, const char *const s2, size_t n) { size_t i; size_t j; i = 0; j = 0; if (!s2 || !ft_strlen(s2)) return ((char *)s1); while (s1[i]) { while (s2[j] == s1[i + j] && i + j < n) { if (j == ft_strlen(s2) - 1) return ((char *)&s1[i]); j++; } j = 0; i++; } return (NULL); }