-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strmapi.c
33 lines (30 loc) · 1.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpoveda- <me@izenynn.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/17 17:47:32 by dpoveda- #+# #+# */
/* Updated: 2023/03/13 17:54:16 by dpoveda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/ft_str.h"
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
char *out;
unsigned int i;
if (!s || !f)
return (NULL);
out = malloc(ft_strlen(s) + 1);
if (!out)
return (NULL);
i = 0;
while (s[i])
{
out[i] = f(i, (char)s[i]);
++i;
}
out[i] = '\0';
return (out);
}