blob: 5239a6f5245a54e612c874e76fdb4fd9b3a118af (
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: joelecle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:07:13 by joelecle #+# #+# */
/* Updated: 2020/02/14 17:07:13 by joelecle ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char
*ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *nstr;
if (!s)
return (NULL);
i = 0;
nstr = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char));
if (!nstr)
return (NULL);
while (s[i])
{
nstr[i] = (*f)(i, s[i]);
i++;
}
return (nstr);
}
|