/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_substr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/20 06:45:32 by narnaud #+# #+# */ /* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" char *ft_substr(char const *s, unsigned int start, size_t len) { size_t i; char *ret; size_t s_size; if (!s) return (NULL); s_size = ft_strlen(s); if (start > s_size) { start = s_size; len = 0; } else if (s_size < start + len) len = s_size - start; ret = ft_calloc(len + 1, sizeof(char)); if (!ret) return (NULL); i = 0; while (i < len && s[start + i]) { ret[i] = s[start + i]; i++; } ret[i] = '\0'; return (ret); }