42_minishell/libftx/libft/ft_strnstr.c
Camille Chauvet 5a102e93a1 init
2023-01-31 14:40:15 +01:00

36 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 13:39:33 by cchauvet #+# #+# */
/* Updated: 2022/09/29 21:10:21 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
if (!*little || (little == big && ft_strlen(little) <= len))
return ((char *) big);
i = 0;
while (i < len && big[i])
{
j = 0;
while (big[i + j] == little[j] && i + j < len)
{
if (!little[j + 1])
return ((char *) big + i);
j++;
}
i++;
}
return (NULL);
}