-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
39 lines (35 loc) · 1.23 KB
/
Copy pathft_strmapi.c
File metadata and controls
39 lines (35 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aerrajiy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 20:57:06 by aerrajiy #+# #+# */
/* Updated: 2022/10/18 22:38:18 by aerrajiy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char f(unsigned int i, char c)
{
return (c - i);
}
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *new;
int i;
if (!s)
return (NULL);
new = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (new != NULL)
{
i = 0;
while (s[i] != '\0')
{
new[i] = (*f)(i, s[i]);
i++;
}
new[i] = '\0';
}
return (new);
}