-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
34 lines (31 loc) 路 1.2 KB
/
Copy pathft_strmapi.c
File metadata and controls
34 lines (31 loc) 路 1.2 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: hceviz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/06 13:16:47 by hceviz #+# #+# */
/* Updated: 2024/12/10 16:29:50 by hceviz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *res;
size_t size;
unsigned int i;
if (!s || !f)
return (NULL);
size = ft_strlen(s);
res = ft_calloc(size + 1, sizeof(char));
if (res == NULL)
return (NULL);
i = 0;
while (s[i])
{
res[i] = f(i, s[i]);
i++;
}
return (res);
}