39 lines
1.3 KiB
C
39 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strnstr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/10/31 10:15:03 by madumerg #+# #+# */
|
|
/* Updated: 2023/11/09 16:25:39 by madumerg ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strnstr(const char *str, const char *to_find, size_t len)
|
|
{
|
|
size_t i;
|
|
int j;
|
|
|
|
i = 0;
|
|
j = 0;
|
|
if (!str)
|
|
return (NULL);
|
|
if (to_find[0] == '\0')
|
|
return ((char *) &str[i]);
|
|
while (str[i] && i < len)
|
|
{
|
|
while (str[i + j] == to_find[j] && i + j < len)
|
|
{
|
|
j++;
|
|
if (to_find[j] == '\0')
|
|
return ((char *) &str[i]);
|
|
}
|
|
j = 0;
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|