-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmap.c
More file actions
41 lines (37 loc) · 1.41 KB
/
Copy pathft_strmap.c
File metadata and controls
41 lines (37 loc) · 1.41 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vinguyen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/10 12:33:55 by vinguyen #+# #+# */
/* Updated: 2019/10/10 12:33:57 by vinguyen ### ########.fr */
/* */
/* ************************************************************************** */
/*
** Applies function f to each char of s to create a new string
** resulting from the successive applications of f
** Param: string to map, function to apply to each char of s
** Return: fresh string created from the successive apps of f
*/
#include "libft.h"
char *ft_strmap(char const *s, char (*f)(char))
{
int len;
int i;
char *output;
i = 0;
if (!s || !f)
return (NULL);
len = ft_strlen(s);
output = ft_memalloc(len + 1);
if (!output)
return (NULL);
while (i < len)
{
output[i] = f(s[i]);
i++;
}
return (output);
}