-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
56 lines (51 loc) · 1.45 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
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ael-haib <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/16 01:15:02 by ael-haib #+# #+# */
/* Updated: 2024/02/01 01:33:14 by ael-haib ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
char *end;
char *original_end;
i = 0;
if (!s)
return (NULL);
while (s[i])
{
i++;
}
end = malloc((i + 1) * sizeof(char));
if (!end)
return (NULL);
end[i] = '\0';
i = 0;
original_end = end;
while (*s)
{
*end = f(i, *s);
end++;
s++;
i++;
}
return (original_end);
}
/*
int main(void)
{
char const *s = "Amineelhaiba";
char *result;
unsigned int i;
i = 0;
result = ft_strmapi(s , ft_new_func);
printf("the result is: %s\n", result);
free(result);
return(0);
} */