35 lines
1.3 KiB
C
Executable file
35 lines
1.3 KiB
C
Executable file
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/15 16:38:47 by thrieg #+# #+# */
|
|
/* Updated: 2025/02/16 19:04:54 by thrieg ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
//I don't know if I have to apply the function to the ending null char...
|
|
//return NULL if any argument is NULL or if any allocation fails
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
char *ret;
|
|
unsigned int i;
|
|
|
|
if (!s || !f)
|
|
return (NULL);
|
|
ret = malloc(sizeof(char) * (ft_strlen(s) + 1));
|
|
if (!ret)
|
|
return (NULL);
|
|
i = 0;
|
|
while (s[i])
|
|
{
|
|
ret[i] = f(i, s[i]);
|
|
i++;
|
|
}
|
|
ret[i] = '\0';
|
|
return (ret);
|
|
}
|