-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
35 lines (32 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elraira- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/17 16:30:28 by elraira- #+# #+# */
/* Updated: 2021/08/17 16:59:12 by elraira- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
unsigned int len;
char *str;
i = 0;
str = (char *)malloc(ft_strlen(s) + 1);
if (!s || !f)
return (0);
len = ft_strlen(s);
if (!str)
return (0);
while (s[i])
{
str[i] = f(i, (char)s[i]);
i++;
}
str[i] = '\0';
return (str);
}