-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
36 lines (33 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysoroko <ysoroko@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/20 18:03:29 by ysoroko #+# #+# */
/* Updated: 2020/12/01 14:26:43 by ysoroko ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *temp_s;
char *my_s;
unsigned int i;
int len;
if (s == 0 || f == 0)
return (0);
temp_s = (char *)s;
i = 0;
len = ft_strlen(temp_s);
if (!(my_s = malloc(sizeof(char) * (len + 1))))
return (0);
my_s[len] = '\0';
while (temp_s[i] != '\0')
{
my_s[i] = f(i, temp_s[i]);
i++;
}
return (my_s);
}