1
0
cub3d/libft/str/ft_strmapi.c

33 lines
1.2 KiB
C
Raw Normal View History

2024-09-10 16:27:06 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:33:40 by madumerg #+# #+# */
/* Updated: 2023/11/08 09:42:37 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *str;
i = 0;
if (!s || !f)
return (NULL);
str = ft_calloc(ft_strlen(s) + 1, sizeof(char));
if (!str)
return (NULL);
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
return (str);
}