You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.2 KiB
32 lines
1.2 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/10/20 16:12:32 by narnaud #+# #+# */
|
|
/* Updated: 2021/11/15 10:52:59 by narnaud ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
unsigned int i;
|
|
char *ret;
|
|
|
|
if (!s)
|
|
return (NULL);
|
|
ret = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char));
|
|
if (!ret)
|
|
return (NULL);
|
|
i = 0;
|
|
while (s[i])
|
|
{
|
|
ret[i] = (*f)(i, s[i]);
|
|
i++;
|
|
}
|
|
return (ret);
|
|
}
|
|
|