-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmap.c
36 lines (33 loc) · 1.33 KB
/
ft_strmap.c
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
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/27 13:13:12 by yochered #+# #+# */
/* Updated: 2018/10/27 13:13:13 by yochered ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <stdlib.h>
char *ft_strmap(char const *s, char (*f)(char))
{
char *fresh_str;
char *fresh_str_tmp;
char *s_tmp;
if (!s)
return (NULL);
s_tmp = (char *)s;
fresh_str = (char *)malloc((ft_strlen(s_tmp) + 1) * sizeof(char));
if (!fresh_str)
return (NULL);
fresh_str_tmp = fresh_str;
while (*s_tmp)
{
*fresh_str++ = f(*s_tmp);
s_tmp++;
}
*fresh_str = '\0';
return (fresh_str_tmp);
}