ft_strtrim.c 1.2 KB

123456789101112131415161718192021222324252627282930
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strtrim.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2014/11/10 18:07:47 by mazimi #+# #+# */
  9. /* Updated: 2016/11/29 14:06:55 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. char *ft_strtrim(char const *s)
  14. {
  15. size_t i;
  16. char *sc;
  17. if (!s)
  18. return (NULL);
  19. sc = ft_strdup(s);
  20. while (*sc == ' ' || *sc == '\n' || *sc == '\t')
  21. sc++;
  22. i = ft_strlen(sc) - 1;
  23. while (sc[i] == ' ' || sc[i] == '\n' || sc[i] == '\t')
  24. i--;
  25. sc[++i] = '\0';
  26. return (sc);
  27. }