/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_substr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: sadjigui +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/06/03 12:11:04 by sadjigui #+# #+# */ /* Updated: 2021/06/07 11:33:45 by sadjigui ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" char *ft_substr(char const *s, unsigned int start, size_t len) { char *str; size_t i; size_t j; i = -1; if (!s) return (NULL); j = ft_strlen(s); if (!len || j <= start) return (ft_strdup("")); str = (char *)malloc(sizeof(char) * len + 1); if (!str) return (NULL); j = 0; while (s[++i] && j < len) { if (i >= start) str[j++] = s[i]; } str[j] = '\0'; return (str); }