-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strmap.c
49 lines (43 loc) · 1.31 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
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jony <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/28 16:33:27 by mhasan #+# #+# */
/* Updated: 2019/11/04 22:03:52 by jony ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmap(char const *s, char (*f)(char))
{
int len;
char *res;
int i;
len = 0;
while (s[len] != '\0')
len++;
res = (char *)malloc(sizeof(*res) * (len + 1));
if (!res)
return (NULL);
i = 0;
while (s[i])
{
res[i] = f(s[i]);
i++;
}
res[i] = '\0';
return (res);
}
char ft_putchar(char c)
{
write(1, &c, 1);
return (0);
}
int main(void)
{
char *str = "hello";
ft_strmap(str, &ft_putchar);
return (0);
}