-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
30 lines (27 loc) · 1.14 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atweek <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/13 15:26:45 by atweek #+# #+# */
/* Updated: 2020/11/13 15:41:56 by atweek ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *dst;
int i;
i = 0;
if ((!s) || !(dst = malloc(sizeof(char) * ft_strlen(s) + 1)))
return (NULL);
while (s[i])
{
dst[i] = f(i, s[i]);
i++;
}
dst[i] = '\0';
return (dst);
}