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