Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_strmapi.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_strmapi.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: raphalme <raphalme@student.42.fr> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2025/12/29 19:07:00 by raphalme #+# #+# */
9
/* Updated: 2026/04/14 10:45:22 by raphalme ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../includes/libft.h"
14
22
char
*
ft_strmapi
(
char
const
*s,
char
(*f)(
unsigned
int
,
char
))
23
{
24
char
*str;
25
unsigned
int
i;
26
size_t
len;
27
28
if
(!s || !f)
29
return
(NULL);
30
len =
ft_strlen
(s);
31
str = (
char
*)malloc(
sizeof
(
char
) * (len + 1));
32
if
(!str)
33
return
(NULL);
34
i = 0;
35
while
(s[i])
36
{
37
str[i] = f(i, s[i]);
38
i++;
39
}
40
str[i] =
'\0'
;
41
return
(str);
42
}
ft_strmapi
char * ft_strmapi(char const *s, char(*f)(unsigned int, char))
Maps a function over a string into a new allocated string.
Definition
ft_strmapi.c:22
ft_strlen
size_t ft_strlen(const char *str)
Returns the length of a null-terminated string.
Definition
ft_strlen.c:21
src
ft_strmapi.c
Generated by
1.9.8