42_solong/libftx/libft/ft_strmapi.c
Camille Chauvet 9e58abcd5c kekw
2022-12-22 17:54:17 +01:00

34 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 22:01:18 by cchauvet #+# #+# */
/* Updated: 2022/09/30 00:53:55 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *out;
size_t i;
if (s == NULL)
return (NULL);
out = malloc((ft_strlen(s) + 1) * sizeof(char));
if (out == NULL)
return (NULL);
i = 0;
while (s[i])
{
out[i] = f(i, s[i]);
i++;
}
out[i] = 0;
return (out);
}