33 lines
1.2 KiB
C
33 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmap.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tchivert <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/04/07 12:33:17 by tchivert #+# #+# */
|
|
/* Updated: 2019/09/04 05:13:33 by tchivert ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strmap(char const *s, char (*f)(char))
|
|
{
|
|
unsigned int i;
|
|
char *dest;
|
|
|
|
i = 0;
|
|
if (!s)
|
|
return (NULL);
|
|
if (!(dest = (char *)malloc(sizeof(char) * ft_strlen((char *)s) + 1)))
|
|
return (NULL);
|
|
while (s[i])
|
|
{
|
|
dest[i] = (*f)((char)s[i]);
|
|
i++;
|
|
}
|
|
dest[i] = '\0';
|
|
return (dest);
|
|
}
|