-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strmapi.c
32 lines (29 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strmapi.c :+: :+: */
/* +:+ */
/* By: ksmorozo <ksmorozo@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/04 20:45:18 by ksmorozo #+# #+# */
/* Updated: 2021/07/07 12:19:10 by ksmorozo ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *new_s;
unsigned int count;
count = 0;
new_s = (char *)malloc(ft_strlen(s) + 1);
if (new_s == NULL)
return (NULL);
while (s[count] != '\0')
{
new_s[count] = (*f)(count, s[count]);
count++;
}
new_s[count] = '\0';
return (new_s);
}