-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
37 lines (34 loc) · 1.22 KB
/
Copy pathft_strmapi.c
File metadata and controls
37 lines (34 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: egarcia- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/11 19:26:07 by egarcia- #+# #+# */
/* Updated: 2019/11/19 18:44:12 by egarcia- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
int i;
i = 0;
if (s)
{
while (s[i])
i++;
if (!(str = (char*)malloc(((i + 1) * sizeof(char)))))
return (NULL);
ft_strlcpy(str, s, i + 1);
i = 0;
while (s[i])
{
str[i] = f(i, str[i]);
i++;
}
return (str);
}
return (NULL);
}