1
Files
Tom CHIVERT 1c9092caaf Norminette
2019-09-04 05:17:54 +02:00

37 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchivert <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 20:27:28 by tchivert #+# #+# */
/* Updated: 2019/09/04 05:13:34 by tchivert ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
unsigned int i;
unsigned int j;
i = 0;
if (!*needle)
return ((char *)haystack);
while (haystack[i] && i < len)
{
if (haystack[i] == needle[0])
{
j = 1;
while (needle[j] && haystack[i + j] == needle[j] && (i + j) < len)
j++;
if (needle[j] == '\0')
return ((char *)haystack + i);
}
i++;
}
return (0);
}