-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
34 lines (32 loc) · 1.23 KB
/
ft_strmapi.c
File metadata and controls
34 lines (32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ouboukou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/08 15:29:42 by ouboukou #+# #+# */
/* Updated: 2023/12/08 18:12:30 by ouboukou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
size_t len;
char *rslt;
size_t i;
if (s == NULL || f == NULL)
return (NULL);
len = ft_strlen(s);
rslt = malloc((len + 1) * sizeof(char));
if (rslt == NULL)
return (NULL);
i = 0;
while (s[i])
{
rslt[i] = f(i, s[i]);
i++;
}
rslt[len] = '\0';
return (rslt);
}