-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
executable file
·49 lines (45 loc) · 1.57 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
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssoeno <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 22:02:50 by ssoeno #+# #+# */
/* Updated: 2024/04/27 06:38:55 by ssoeno ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
unsigned int length;
char *res;
if (!s || !f)
return (NULL);
length = ft_strlen(s);
res = malloc(sizeof(char) * length + 1);
if (!res)
return (NULL);
i = 0;
while (i < length)
{
res[i] = (*f)(i, s[i]);
i++;
}
res[i] = '\0';
return (res);
}
// char toupper_adapter(unsigned int index, char c) {
// (void)index;
// return (char)ft_toupper((int)c);
// }
// int main() {
// const char *input = "hello world";
// char *result;
// result = ft_strmapi(input, toupper_adapter);
// printf("Original: %s\n", input);
// printf("Uppercase: %s\n", result);
// free(result);
// return 0;
// }