32 lines
1.2 KiB
C
32 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2015/11/28 21:39:30 by gbrochar #+# #+# */
|
|
/* Updated: 2015/12/02 16:22:05 by gbrochar ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
char *str;
|
|
unsigned int i;
|
|
|
|
i = 0;
|
|
str = (char *)malloc((ft_strlen(s) + 1) * sizeof(char));
|
|
if (!str)
|
|
return (NULL);
|
|
while (s[i])
|
|
{
|
|
str[i] = f(i, s[i]);
|
|
i++;
|
|
}
|
|
str[i] = '\0';
|
|
return (str);
|
|
}
|