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

char *
ft_strmapi (char const *s, char (*f) (unsigned int, char))
{
  size_t len;
  char *result;
  size_t i;

  len = ft_strlen (s);
  result = malloc (len + 1);
  if (!result)
    return (NULL);
  i = 0;
  while (i < len)
    {
      result[i] = f (i, s[i]);
      i++;
    }
  result[len] = '\0';
  return (result);
}