ft_strstr.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strstr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2014/12/08 19:33:30 by mazimi #+# #+# */
  9. /* Updated: 2015/09/16 16:05:35 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. char *ft_strstr(const char *s1, const char *s2)
  14. {
  15. int i;
  16. int j;
  17. int k;
  18. k = 0;
  19. i = 0;
  20. if (s2[0] == 0)
  21. return ((char *)s1);
  22. while (s1[i])
  23. {
  24. j = 0;
  25. if (s1[i] == s2[j])
  26. {
  27. k = i;
  28. while (s1[k] == s2[j] && s2[j])
  29. {
  30. k++;
  31. j++;
  32. }
  33. if (s2[j] == '\0')
  34. return ((char *)s1 + i);
  35. }
  36. i++;
  37. }
  38. return (NULL);
  39. }