Files
libft/ft_strnstr.c
2026-08-31 02:16:33 +02:00

33 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rzy <ry@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/08/23 23:27:28 by rzy #+# #+# */
/* Updated: 2026/08/23 23:33:18 by rzy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t n)
{
size_t i;
size_t j;
if (!needle[0])
return ((char *)(haystack));
i = 0;
while (i < n && haystack[i])
{
j = 0;
while (i + j < n && needle[j] && haystack[i + j] == needle[j])
++j;
if (!needle[j])
return ((char *)&haystack[i]);
++i;
}
return (NULL);
}