Skip to content

Commit

Permalink
ft_strnstr, done!
Browse files Browse the repository at this point in the history
  • Loading branch information
Joarell committed Oct 25, 2021
1 parent 30e96dd commit 8317a3c
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions ft_strnstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,27 @@
/* By: Jev <jsouza-c@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/14 00:12:54 by Jev #+# #+# */
/* Updated: 2021/10/17 16:12:10 by Jev ### ########.fr */
/* Updated: 2021/10/24 21:50:26 by Jev ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

char *ft_strnstr(const char *big, const char *little, size_t len)
{
char *aux;
size_t range;

range = ft_strlen(little);
if (!*little)
{
return ((char *) big);
}
while (*big != *little)
{
if (len == 0 || !*big)
return (NULL);
big++;
len--;
}
aux = (char *) big;
while (*little != '\0')
while (*big && range <= len)
{
if (len == 0 || *big != *little)
if (!ft_strncmp(big, little, range))
{
return (NULL);
return ((char *) big);
}
big++;
little++;
len--;
}
return (aux);
return (NULL);
}

0 comments on commit 8317a3c

Please sign in to comment.