-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
44 lines (39 loc) · 1.34 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
36
37
38
39
40
41
42
43
44
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elel-yak <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/19 20:54:18 by elel-yak #+# #+# */
/* Updated: 2022/10/22 13:23:12 by elel-yak ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *result;
unsigned int i;
if (!s || !f)
return (0);
result = malloc(ft_strlen(s) + 1);
if (!result)
return (0);
i = 0;
while (s[i])
{
result[i] = f(i, s[i]);
i++;
}
result[i] = '\0';
return (result);
}
// char f(unsigned int i, char c)
// {
// return(c + 'a' - '0');
// }
// int main()
// {
// char str[] = "0123456789";
// printf("%s\n", ft_strmapi(str, &f));
// }