-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
46 lines (40 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yabenman <yabenman@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 06:49:21 by yabenman #+# #+# */
/* Updated: 2024/11/02 04:03:09 by yabenman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f) (unsigned int, char))
{
unsigned int index;
char *str;
index = 0;
if (!s)
return (NULL);
str = (char *)malloc(ft_strlen(s) + 1);
if (str == NULL)
return (NULL);
while (s[index] != '\0')
{
str[index] = f(index, s[index]);
index++;
}
str[index] = '\0';
return (str);
}
// #include <stdio.h>
// char shift(unsigned int i, char c)
// {
// return c + 1;
// }
// int main()
// {
// char str[] = "absddzed";
// printf("%s\n",ft_strmapi(str, shift));
// }