-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
40 lines (36 loc) · 1.38 KB
/
ft_strmapi.c
File metadata and controls
40 lines (36 loc) · 1.38 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
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bnoufel <bnoufel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 16:09:02 by bnoufel #+# #+# */
/* Updated: 2020/02/08 19:49:38 by bnoufel ### ########.fr */
/* */
/* ************************************************************************** */
#include "str.h"
/*
** ft_strmapi Apply the function f to each character of the character string
** passed in
** parameter by specifying its index to create a new “fresh” string (with
** malloc (3)) resulting from the successive applications of f.
** @param s
** @param f
** @return
*/
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
uint32_t i;
char *str;
str = ft_strnew(ft_strlen(s) + 1);
if (!str)
return (NULL);
i = 0;
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
return (str);
}