-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
43 lines (38 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldel-val <[email protected]> +#+ +:+ +#+ */
/* +#+#P#+#+#+ +#+ */
/* Created: 2024/10/04 19:03:28 by ldel-val #+# #+# */
/* Updated: 2024/10/05 10:35:46 by ldel-val ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
char *result;
i = 0;
result = ft_calloc(ft_strlen(s) + 1, sizeof(char));
if (!result)
return (NULL);
while (s[i])
{
result[i] = f(i, s[i]);
i ++;
}
return (result);
}
/*
char ft_toupper2(unsigned int index, char c)
{
(void)index;
return (ft_toupper(c));
}
int main(void)
{
char str[] = "hola twitter soy mapi";
printf("%s", ft_strmapi(str, ft_toupper2));
}*/