-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strmapi.c
28 lines (25 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: matlopes <matlopes@student.42.rio> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 09:42:26 by matlopes #+# #+# */
/* Updated: 2023/11/07 13:48:20 by matlopes ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *pointer;
int counter;
pointer = malloc((ft_strlen(s) + 1) * sizeof(char));
if (!pointer)
return (NULL);
counter = -1;
while (s[++counter] != '\0')
pointer[counter] = (*f)(counter, s[counter]);
pointer[counter] = '\0';
return (pointer);
}