34 lines
1.2 KiB
C
34 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2018/11/14 21:18:03 by hulamy #+# #+# */
|
|
/* Updated: 2019/03/25 15:28:21 by hulamy ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
/*
|
|
** create a new array with the result of function f
|
|
** on every element of s by index i
|
|
*/
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
char *str;
|
|
int i;
|
|
|
|
if (!s)
|
|
return (NULL);
|
|
if (!(str = ft_strnew(ft_strlen(s))))
|
|
return (NULL);
|
|
i = -1;
|
|
while (s[++i])
|
|
str[i] = f(i, s[i]);
|
|
return (str);
|
|
}
|