-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
49 lines (45 loc) · 1.52 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: anamartinez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 17:31:01 by anamartinez #+# #+# */
/* Updated: 2023/05/03 18:11:46 by anamartinez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
const int len = (int)ft_strlen(s);
char *result;
unsigned int i;
if (!s || !f)
return (NULL);
result = malloc((len + 1) * sizeof(char));
if (result == NULL)
return (NULL);
i = 0;
while (s[i])
{
result[i] = f(i, s[i]);
i++;
}
result[i] = '\0';
return (result);
}
// char to_upper_character(unsigned int indice, char c)
// {
// (void)indice;
// if (c >= 'a' && c <= 'z') {
// return c - 32;
// }
// return c;
// }
// int main(void)
// {
// char *str = "LoReM iPsUm";
// printf("Result: %s", ft_strmapi(str, &mapi));
// return (0);
// }∫