libft_old/extended_libft/ft_strmapi.c
Willem Haffmans 326f52308e all
2024-07-26 22:32:04 +02:00

35 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 18:42:10 by whaffman #+# #+# */
/* Updated: 2024/07/10 16:06:40 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
char *result;
if (!s)
return (NULL);
result = malloc((ft_strlen(s) + 1) * sizeof(char));
if (!result)
return (NULL);
i = 0;
while (s[i])
{
result[i] = f(i, s[i]);
i++;
}
result[i] = '\0';
return (result);
}