-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
36 lines (33 loc) · 1.28 KB
/
ft_strmapi.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
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_strmapi.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: thperchi <[email protected]> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/07/11 03:05:19 by thperchi #+# ## ## #+# */
/* Updated: 2018/10/11 17:44:26 by thperchi ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int x;
char *str;
x = 0;
if (s == NULL)
return (NULL);
while (s[x])
x++;
if (!(str = (char *)malloc(sizeof(char) * (x + 1))))
return (NULL);
x = 0;
while (s[x])
{
str[x] = f(x, s[x]);
x++;
}
str[x] = '\0';
return (str);
}