Archived
1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
FDF/libft/ft_strnstr.c

36 lines
1.3 KiB
C
Raw Normal View History

2023-12-18 17:19:34 +01:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 16:02:17 by adjoly #+# #+# */
/* Updated: 2023/11/12 16:17:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
i = 0;
if (!big && len == 0)
return (NULL);
if (*little == '\0' || little == big)
return ((char *)big);
while (i < len && big[i])
{
j = 0;
while (big[i + j] == little[j] && little[j] && big[i] && i + j < len)
j++;
if (little[j] == 0)
return ((char *)big + i);
i++;
}
return (NULL);
}