32 lines
1.2 KiB
C
32 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */
|
|
/* Updated: 2023/10/03 15:20:49 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
#include "libft.h"
|
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
char *dest;
|
|
unsigned int i;
|
|
|
|
dest = malloc((ft_strlen(s) + 1) * sizeof(char));
|
|
if (!dest)
|
|
return (NULL);
|
|
i = 0;
|
|
while (s[i])
|
|
{
|
|
dest[i] = (*f)(i, s[i]);
|
|
i++;
|
|
}
|
|
dest[i] = '\0';
|
|
return (dest);
|
|
}
|