-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
45 lines (40 loc) · 1.33 KB
/
ft_strmapi.c
File metadata and controls
45 lines (40 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lcosta-g <lcosta-g@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/09 13:17:12 by lcosta-g #+# #+# */
/* Updated: 2024/10/31 12:11:49 by lcosta-g ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
size_t i;
str = (char *)malloc(ft_strlen(s) + 1);
if (!s || !f || !str)
return (NULL);
i = 0;
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
str[i] = '\0';
return (str);
}
/*
static char strmapi_tester(unsigned int i, char c)
{
return (i + c);
}
#include <stdio.h>
int main(void)
{
printf("%s\n", ft_strmapi("teste", &strmapi_tester));
return (0);
}
*/