-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
33 lines (30 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: schetty <schetty@student.42kl.edu.my> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/10 15:28:46 by schetty #+# #+# */
/* Updated: 2021/11/11 22:23:36 by schetty ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int len;
char *str;
if (!s || !f)
return (NULL);
len = 0;
while (s[len])
len++;
str = malloc(sizeof(char) * (len + 1));
if (str)
{
str[len] = '\0';
while (len--)
str[len] = f(len, s[len]);
}
return (str);
}