-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmap.c
38 lines (35 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvenance <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/26 18:39:59 by vvenance #+# #+# */
/* Updated: 2015/12/14 15:52:17 by vvenance ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmap(char const *s, char (*f)(char))
{
int i;
char *nstr;
i = ft_strlen(s);
nstr = ft_memalloc(i + 1);
if (nstr == NULL)
return (NULL);
i = 0;
while (s[i] != '\0')
{
nstr[i] = s[i];
i++;
}
nstr[i] = '\0';
i = 0;
while (nstr[i] != '\0')
{
nstr[i] = f(nstr[i]);
i++;
}
return (nstr);
}