ft_strmapi - gabrielcoelhodacunha-old/42sp-libft GitHub Wiki
Description
Creates a new string by applying the function f
to each character of s
.
Implementation
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *result;
unsigned int idx;
if (!s)
return (NULL);
result = malloc((ft_strlen(s) + 1) * sizeof(char));
if (!result)
return (NULL);
idx = -1;
while (s[++idx])
result[idx] = f(idx, s[idx]);
result[idx] = '\0';
return (result);
}