ft_strcorr.c 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strcorr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2016/12/13 21:19:40 by bchanot #+# #+# */
  9. /* Updated: 2018/10/29 12:12:48 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. char *ft_strcorr(const char *const src, const char c)
  14. {
  15. int len;
  16. int i;
  17. i = 0;
  18. if (!src || !c)
  19. return (NULL);
  20. while (src[i] && src[i] == c)
  21. i++;
  22. if (!src[i])
  23. return (NULL);
  24. len = ft_strlen(src) - 1;
  25. while (len > 0 && src[len] == c)
  26. len--;
  27. len++;
  28. return (ft_strsub(src, i, len - i));
  29. }