You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
1.2 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 15:25:31 by emartine #+# #+# */
/* Updated: 2017/11/08 15:25:32 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmap(char const *s, char (*f)(char))
{
char *r;
size_t l;
size_t i;
if (!s || !f)
return (NULL);
l = ft_strlen(s);
if (!(r = (char *)malloc(l + 1)))
return (NULL);
i = 0;
while (i < l)
{
r[i] = f(s[i]);
i++;
}
r[i] = '\0';
return (r);
}