init
This commit is contained in:
35
libftx/libft/ft_strnstr.c
Normal file
35
libftx/libft/ft_strnstr.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 13:39:33 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 21:10:21 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
if (!*little || (little == big && ft_strlen(little) <= len))
|
||||
return ((char *) big);
|
||||
i = 0;
|
||||
while (i < len && big[i])
|
||||
{
|
||||
j = 0;
|
||||
while (big[i + j] == little[j] && i + j < len)
|
||||
{
|
||||
if (!little[j + 1])
|
||||
return ((char *) big + i);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user