34 lines
1.2 KiB
C
Executable File
34 lines
1.2 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/11/01 03:54:38 by tomoron #+# #+# */
|
|
/* Updated: 2023/11/01 14:06:34 by tomoron ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
int i;
|
|
char *res;
|
|
|
|
i = 0;
|
|
if (!s)
|
|
return (0);
|
|
res = malloc((ft_strlen(s) + 1) * sizeof(char));
|
|
if (!res)
|
|
return (res);
|
|
while (s[i])
|
|
{
|
|
res[i] = f(i, s[i]);
|
|
i++;
|
|
}
|
|
res[i] = 0;
|
|
return (res);
|
|
}
|