-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
40 lines (37 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
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aazeroua <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/09 15:41:15 by aazeroua #+# #+# */
/* Updated: 2019/04/18 19:31:21 by aazeroua ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
char *as;
i = 0;
as = NULL;
if (!s)
return (NULL);
if (s)
{
as = (char *)malloc(sizeof(char) * ft_strlen(s) + 1);
if (as == NULL)
return (NULL);
else
{
while (s[i])
{
as[i] = f(i, s[i]);
i++;
}
}
}
as[i] = '\0';
return (as);
}