-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
36 lines (33 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybitton <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 15:47:47 by ybitton #+# #+# */
/* Updated: 2016/12/15 18:42:25 by ybitton ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *c;
unsigned int i;
if (s != NULL && f != NULL)
{
c = ft_strdup((char *)s);
if (!c)
return (NULL);
i = 0;
while (s[i])
{
c[i] = (*f)(i, c[i]);
i++;
}
c[i] = '\0';
return (c);
}
else
return (NULL);
}