-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmap.c
executable file
·39 lines (35 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/15 23:11:39 by mwilliam #+# #+# */
/* Updated: 2016/12/06 19:48:46 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Applies the function f to each character of the string
** and creates a "fresh" string
*/
char *ft_strmap(char const *s, char (*f)(char))
{
char *fresh;
int index;
fresh = NULL;
index = 0;
if (s)
{
if (!(fresh = (char *)malloc(sizeof(char) * ft_strlen(s) + 1)))
return (NULL);
while (s[index])
{
fresh[index] = f(s[index]);
index++;
}
fresh[index] = '\0';
}
return (fresh);
}