-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
30 lines (27 loc) · 1.11 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cprune <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/30 11:33:18 by cprune #+# #+# */
/* Updated: 2015/12/05 18:23:42 by cprune ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
char *s2;
i = 0;
if (!(s2 = ft_strnew(ft_strlen(s))))
return (NULL);
while (s[i])
{
s2[i] = f(i, s[i]);
i++;
}
s2[i] = '\0';
return (s2);
}