-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
50 lines (43 loc) · 1.48 KB
/
Copy pathft_strmapi.c
File metadata and controls
50 lines (43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ledias-d <ledias-d@student.42.rio> #+# +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024-10-11 12:59:13 by ledias-d #+# #+# */
/* Updated: 2024-10-11 12:59:13 by ledias-d ### ########.rio */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
char *ptr;
unsigned int i;
ptr = (char *)malloc((ft_strlen(s) + 1) * sizeof(char));
if (!ptr)
return (NULL);
i = 0;
while (s[i])
{
ptr[i] = f(i, s[i]);
i++;
}
ptr[i] = '\0';
return (ptr);
}
/*char to_upper_odd_index(unsigned int i, char c)
{
if (i % 2 == 1 && c >= 'a' && c <= 'z')
return (c - 32);
return (c);
}
#include <stdio.h>
int main(void)
{
char *str = "abcdef";
char *result = ft_strmapi(str, to_upper_odd_index);
printf("Resultado: %s\n", result);
free(result);
return (0);
}*/