-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
executable file
·37 lines (34 loc) · 1.24 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: mberger <mberger@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/11 18:57:18 by mberger #+# #+# */
/* Updated: 2016/03/09 14:18:48 by mberger ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *s1;
char *save;
unsigned int i;
i = 0;
if (s == NULL)
return (NULL);
s1 = (char *)malloc(sizeof(char) * (ft_strlen(s) + 1));
if (s1 == NULL)
return (NULL);
save = s1;
while (*s != '\0')
{
*save = (*f)(i, *s);
save++;
s++;
i++;
}
*save = '\0';
return (s1);
}