aboutsummaryrefslogtreecommitdiff
path: root/ft_strmap.c
blob: 7fc3051e805c5dfe809f2275d611200fdd457945 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdlib.h>
#include "libft.h"

char    *ft_strmap(char const *s, char (*f)(char))
{
    size_t  i;
    size_t  len;
    char    *mapped;

    len = ft_strlen(s);
    if ((mapped = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
        return (NULL);
    i = 0;
    while (i < len)
    {
        mapped[i] = (*f)(s[i]);
        i++;
    }
    mapped[i] = '\0';
    return (mapped);
}