-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
55 lines (49 loc) · 1.48 KB
/
ft_strmapi.c
File metadata and controls
55 lines (49 loc) · 1.48 KB
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
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rafael-m <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/11 13:21:20 by rafael-m #+# #+# */
/* Updated: 2025/04/19 16:40:14 by rafael-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*#include <stdio.h>
static char to_uppercase_i(unsigned int index, char c)
{
if (c >= 'a' && c <= 'z')
{
return (c - 32 + index);
}
return (c);
}
*/
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
size_t i;
size_t lg;
char *r;
i = 0;
lg = ft_strlen((char *)s);
r = (char *)malloc((ft_strlen((char *)s) + 1) * sizeof(char));
if (!r)
return (NULL);
while (i < lg)
{
r[i] = f((unsigned int)i, s[i]);
i++;
}
r[i] = '\0';
return (r);
}
/*
int main(void)
{
char *s;
s = ft_strmapi("asdasda", to_uppercase_i);
printf("ft_strmapi = %s\n", s);
free (s);
}
*/