/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strmapi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/20 21:51:01 by grobledo #+# #+# */ /* Updated: 2023/02/20 21:51:02 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) { size_t i; size_t dlen; char *dest; if (!s || !(*f)) return (NULL); i = 0; dlen = ft_strlen(s); dest = ft_calloc(dlen + 1, sizeof (char)); if (!dest) return (NULL); while (i < ft_strlen(s)) { dest[i] = (*f)(i, s[i]); i++; } return (dest); }