-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
28 lines (25 loc) · 1.16 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aahlyel <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/19 05:26:24 by aahlyel #+# #+# */
/* Updated: 2022/10/27 01:39:36 by aahlyel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *str;
if (!s || !f)
return (NULL);
i = -1;
str = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char));
if (str)
while (*(s + ++i))
*(str + i) = f(i, *(s + i));
return (str);
}