philosopher/libft/ft_strmapi.c
2023-03-06 17:38:20 +01:00

33 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:55:32 by erey-bet #+# #+# */
/* Updated: 2022/10/10 15:43:18 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *str;
if (s == NULL || f == NULL)
return (NULL);
str = ft_strdup(s);
if (str == NULL)
return (NULL);
i = 0;
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
return (str);
}