blob: 71d77e46d780329b067715b7ca17b7573eaf4143 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:29:32 by cacharle #+# #+# */
/* Updated: 2019/11/20 04:02:15 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char *s, char (*f)(unsigned int, char))
{
size_t i;
size_t len;
char *mapped;
if (s == NULL || f == NULL)
return (NULL);
len = ft_strlen(s);
if ((mapped = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
return (NULL);
i = 0;
while (i < len)
{
mapped[i] = (*f)((unsigned int)i, s[i]);
i++;
}
mapped[i] = '\0';
return (mapped);
}
|