ft_strstr.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strstr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2015/11/23 16:41:28 by bchanot #+# #+# */
  9. /* Updated: 2018/10/13 22:51:57 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. char *ft_strstr(const char *s1, const char *s2)
  14. {
  15. size_t size;
  16. size_t i;
  17. size_t j;
  18. i = 0;
  19. j = 0;
  20. size = ft_strlen(s2);
  21. if (size == 0)
  22. return ((char *)s1);
  23. while (s1[i])
  24. {
  25. while (s2[j] == s1[i + j])
  26. {
  27. if (j == size - 1)
  28. return ((char *)&s1[i]);
  29. j++;
  30. }
  31. j = 0;
  32. i++;
  33. }
  34. return (NULL);
  35. }