/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_substr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: vvobis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/04 18:58:25 by vvobis #+# #+# */ /* Updated: 2024/04/09 21:50:44 by vvobis ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" char *ft_substr(char const *s, unsigned int start, size_t len) { char *tmp; unsigned int i; i = 0; if (!s || start >= ft_strlen(s) || len <= 0) { tmp = malloc(1); if (!tmp) return (NULL); tmp[i] = 0; return (tmp); } if (len + start > ft_strlen(s)) len = ft_strlen(s) - start; tmp = malloc(sizeof(*tmp) * len + 1); if (!tmp) return (NULL); while (i < len && s[i]) { tmp[i] = s[i + start]; i++; } tmp[i] = 0; return (tmp); }