-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
39 lines (36 loc) · 1.22 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
37
38
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnichol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/07 15:45:20 by dnichol #+# #+# */
/* Updated: 2019/09/07 17:00:42 by dnichol ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s,
char (*f)(unsigned int, char))
{
unsigned int i;
char *dest;
i = 0;
if (s != NULL && f != NULL)
{
dest = ft_strnew(ft_strlen(s));
if (dest != NULL)
{
while (s[i] != '\0')
{
dest[i] = f(i, s[i]);
i++;
}
return (dest);
}
else
return (NULL);
}
else
return (NULL);
}