libft
src
ft_strmapi.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* ft_strmapi.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2019/09/05 00:46:53 by unite #+# #+# */
10
/* Updated: 2020/07/16 02:41:08 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
libft.h
"
15
28
char
*
ft_strmapi
(
char
const
*s,
char
(*f)(
unsigned
int
,
char
))
29
{
30
char
*s_new;
31
size_t
i;
32
33
if
(!s || !f)
34
return
(NULL);
35
s_new =
ft_strdup
(s);
36
if
(!s_new)
37
return
(NULL);
38
i = 0;
39
while
(s[i])
40
{
41
s_new[i] = f(i, s[i]);
42
i++;
43
}
44
return
(s_new);
45
}
ft_strdup
char * ft_strdup(const char *s1)
Replicates behaviour of strdup from libc.
Definition:
ft_strdup.c:20
ft_strmapi
char * ft_strmapi(char const *s, char(*f)(unsigned int, char))
Maps a function to characters of a string and their indices Applies the function f to each character ...
Definition:
ft_strmapi.c:28
libft.h
Generated by
1.8.16