-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
33 lines (30 loc) · 1.18 KB
/
Copy pathft_strmapi.c
File metadata and controls
33 lines (30 loc) · 1.18 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asandy <asandy@student.42abudhabi.ae> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/07 22:41:04 by asandy #+# #+# */
/* Updated: 2022/02/08 06:43:07 by asandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int n;
char *ptr;
if (!s || !f)
return (NULL);
n = 0;
ptr = malloc (sizeof(char) *(ft_strlen(s) + 1));
if (!ptr)
return (NULL);
while (s[n])
{
ptr[n] = (f)(n, s[n]);
n++;
}
ptr[n] = '\0';
return (ptr);
}