diff options
Diffstat (limited to 'libft/ft_strmapi.c')
-rw-r--r-- | libft/ft_strmapi.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100644 index 0000000..f769325 --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kdx <kdx @student.42angouleme.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/09/28 20:06:57 by kdx #+# #+# */ +/* Updated: 2022/10/14 02:25:55 by kdx ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *copy; + size_t i; + + if (s == NULL || f == NULL) + return (NULL); + copy = ft_strdup(s); + if (copy == NULL) + return (NULL); + i = 0; + while (copy[i] != '\0') + { + copy[i] = f(i, copy[i]); + i += 1; + } + return (copy); +} |