ft_dup_first_word.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_dup_first_word.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2017/12/04 22:56:53 by bchanot #+# #+# */
  9. /* Updated: 2018/10/13 20:16:50 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. char *ft_dup_first_word(const char *src)
  14. {
  15. const char *tmp;
  16. size_t i;
  17. char *ret;
  18. tmp = src;
  19. i = 0;
  20. while (*tmp && ((*tmp >= 7 && *tmp <= 13) || *tmp == ' '))
  21. tmp++;
  22. while (*tmp && ((*tmp < 7 || *tmp > 13) && *tmp != ' '))
  23. {
  24. tmp++;
  25. i++;
  26. }
  27. if (!(ret = ft_strnew(i)))
  28. return (NULL);
  29. tmp = src;
  30. i = 0;
  31. while (*tmp && ((*tmp >= 7 && *tmp <= 13) || *tmp == ' '))
  32. tmp++;
  33. while (*tmp && ((*tmp < 7 || *tmp > 13) && *tmp != ' '))
  34. {
  35. ret[i++] = *tmp;
  36. tmp++;
  37. }
  38. return (ret);
  39. }