2022-09-27 11:25:41 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
2022-10-04 08:21:55 -04:00
|
|
|
/* ft_strmapi.c :+: :+: :+: */
|
2022-09-27 11:25:41 -04:00
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
2022-10-04 08:21:55 -04:00
|
|
|
/* Created: 2022/09/29 22:01:18 by cchauvet #+# #+# */
|
|
|
|
/* Updated: 2022/09/30 00:53:55 by cchauvet ### ########.fr */
|
2022-09-27 11:25:41 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "libft.h"
|
|
|
|
|
2022-10-04 08:21:55 -04:00
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
2022-09-27 11:25:41 -04:00
|
|
|
{
|
2022-10-04 08:21:55 -04:00
|
|
|
char *out;
|
|
|
|
size_t i;
|
2022-09-27 11:25:41 -04:00
|
|
|
|
2022-10-04 08:21:55 -04:00
|
|
|
if (s == NULL)
|
|
|
|
return (NULL);
|
|
|
|
out = malloc((ft_strlen(s) + 1) * sizeof(char));
|
|
|
|
if (out == NULL)
|
|
|
|
return (NULL);
|
|
|
|
i = 0;
|
|
|
|
while (s[i])
|
|
|
|
{
|
|
|
|
out[i] = f(i, s[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
out[i] = 0;
|
|
|
|
return (out);
|
2022-09-27 11:25:41 -04:00
|
|
|
}
|