lang/lib/libft/ft_strmapi.c
2025-05-14 17:53:43 +02:00

34 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/07 17:01:35 by vvobis #+# #+# */
/* Updated: 2024/04/12 10:13:57 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *tmp;
unsigned int i;
if (!s || !f)
return (NULL);
tmp = ft_calloc(ft_strlen(s) + 1, sizeof(*tmp));
if (!tmp)
return (NULL);
i = 0;
while (s[i])
{
tmp[i] = f(i, s[i]);
i++;
}
tmp[i] = 0;
return (tmp);
}