-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_strmapi.c
34 lines (31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hbaddrul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/07 21:58:53 by hbaddrul #+# #+# */
/* Updated: 2021/11/21 20:37:54 by hbaddrul ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
char *ret;
unsigned int i;
if (!s)
return (0);
ret = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!ret)
return (0);
i = 0;
while (s[i])
{
ret[i] = f(i, s[i]);
++i;
}
ret[i] = 0;
return (ret);
}