-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
38 lines (35 loc) · 1.25 KB
/
ft_strmapi.c
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
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: delin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/21 16:10:28 by delin #+# #+# */
/* Updated: 2018/04/28 15:45:22 by delin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int len;
unsigned int i;
char *tmp;
if (!s)
return (NULL);
if (!f)
return (ft_strdup(s));
i = 0;
len = ft_strlen(s);
tmp = (char *)malloc(sizeof(char) * (len + 1));
if (tmp)
{
while (i < len)
{
tmp[i] = (*f)(i, s[i]);
i = i + 1;
}
tmp[i] = '\0';
}
return (tmp);
}