-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
48 lines (44 loc) · 1.51 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
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edegraev <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 14:54:53 by edegraev #+# #+# */
/* Updated: 2023/11/13 14:29:12 by edegraev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
int i;
if (!s || !f)
return (0);
str = (char *)malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!str)
return (0);
i = 0;
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
str[i] = '\0';
return (str);
}
// #include <stdio.h>
// char my_fn(unsigned int i, char str)
// {
// printf("index : %d string : %c\n", i, str);
// return (str - 32);
// }
// int main(void)
// {
// char str[10] = "hello.";
// printf("The result is %s\n", str);
// char *result = ft_strmapi(str, my_fn);
// printf("The result is %s\n", result);
// return (0);
// }