42_cub3d/Libft/ft_strmapi.c
2024-10-09 03:35:09 +02:00

33 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}