cub3d/libft/src/ft_strmapi.c

34 lines
1.2 KiB
C
Raw Normal View History

2023-10-25 13:56:45 +02:00
/* ************************************************************************** */
/* */
/* :::::::: */
2023-10-26 19:11:30 +02:00
/* ft_strmapi.c :+: :+: */
2023-10-25 13:56:45 +02:00
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/13 03:04:33 by djonker #+# #+# */
2023-10-26 19:11:30 +02:00
/* Updated: 2023/10/18 17:00:19 by houtworm ######## odam.nl */
2023-10-25 13:56:45 +02:00
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *r;
i = 0;
if (f == NULL || s == NULL)
return (0x0);
r = (char *)malloc(sizeof(char) * (ft_strlen((char *)s)) + 1);
if (r == NULL)
return (r);
while (s[i] != '\0')
{
r[i] = f(i, s[i]);
i++;
}
r[i] = '\0';
return (r);
}