-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strmapi.c
51 lines (46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuotsuka <yuotsuka@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 21:05:21 by yuotsuka #+# #+# */
/* Updated: 2024/05/24 09:10:51 by yuotsuka ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
size_t i;
char *(str), *result;
if (!s)
return (NULL);
str = (char *)malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!str)
return (NULL);
i = 0;
result = str;
while (*s)
*str++ = f(i++, *s++);
*str = '\0';
return (result);
}
/*
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
char *str;
i = 0;
if (!s || !f)
return (NULL);
ft_strlcpy(str, s, ft_strlen(str));
while (str[i] != 0)
{
*str = (*f)(i++, *s++);
i++;
}
str[i] = '\0';
return (str);
}
*/