37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strnstr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: scebula <scebula@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2015/11/26 17:53:36 by scebula #+# #+# */
|
|
/* Updated: 2015/12/04 00:41:10 by scebula ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strnstr(const char *s1, const char *s2, size_t n)
|
|
{
|
|
size_t i;
|
|
size_t j;
|
|
|
|
i = 0;
|
|
j = 0;
|
|
if (!*s2)
|
|
return ((char *)s1);
|
|
while (s1[i] && i < n)
|
|
{
|
|
j = 0;
|
|
while (s1[i + j] == s2[j] && (i + j) < n)
|
|
{
|
|
j++;
|
|
if (!s2[j])
|
|
return ((char *)s1 + i);
|
|
}
|
|
i++;
|
|
}
|
|
return (NULL);
|
|
}
|