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