-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
51 lines (45 loc) · 1.43 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
40
41
42
43
44
45
46
47
48
49
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbin-nas <mbin-nas@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/01 13:46:55 by mbin-nas #+# #+# */
/* Updated: 2022/08/01 13:46:58 by mbin-nas ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *str, char (*f)(unsigned int, char))
{
int i;
char *str1;
i = 0;
if (!str || !f)
return (0);
str1 = malloc(ft_strlen(str) + 1);
if (!str1 || str1 == NULL)
return (NULL);
while (str1 != NULL && str[i] != '\0')
{
str1[i] = f(i, str[i]);
i++;
}
str1[i] = '\0';
return (str1);
}
char f(unsigned int i, char c)
{
char str;
i = 2;
str = c + i;
return (str);
}
// int main()
// {
// char str1[] = "abc";
// char* str2;
// str2 = ft_strmapi(str1, *f);
// printf("%s\n", str2);
// return(0);
// }