42_minitalk/libftx/libft/ft_strnstr.c

36 lines
1.3 KiB
C
Raw Normal View History

2023-01-23 07:22:30 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}