ft_strnstr.c 1.2 KB

12345678910111213141516171819202122232425
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strnstr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2014/11/08 15:26:53 by mazimi #+# #+# */
  9. /* Updated: 2014/12/08 17:21:39 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. char *ft_strnstr(const char *s1, const char *s2, size_t n)
  14. {
  15. if (!*s2)
  16. return ((char *)s1);
  17. if (!*s1 || n == 0)
  18. return (NULL);
  19. if (*s1 == *s2)
  20. if (ft_strnstr(s1 + 1, s2 + 1, n - 1) - 1 == s1)
  21. return ((char *)s1);
  22. return (ft_strnstr(s1 + 1, s2, n - 1));
  23. }