-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
executable file
·30 lines (27 loc) · 1.18 KB
/
ft_strmapi.c
File metadata and controls
executable file
·30 lines (27 loc) · 1.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: luperez <luperez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/15 18:55:24 by luperez #+# #+# */
/* Updated: 2014/11/19 07:24:04 by luperez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *p;
size_t len;
if (s == NULL || f == NULL)
return (NULL);
i = -1;
len = ft_strlen(s) + 1;
p = (char *)malloc(sizeof(char) * len);
while (s[++i])
p[i] = f(i, s[i]);
p[i] = '\0';
return (p);
}