-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
37 lines (34 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alaulom <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/12 10:57:24 by alaulom #+# #+# */
/* Updated: 2014/11/12 11:34:06 by alaulom ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
char *str;
unsigned int i;
size_t l;
if (s && f)
{
l = ft_strlen(s);
str = (char *)malloc(sizeof(char) * (l + 1));
if (!str)
return (NULL);
i = 0;
while (i < l)
{
str[i] = (*f)(i, *s++);
i++;
}
str[i] = 0;
return (str);
}
return (NULL);
}