-
Notifications
You must be signed in to change notification settings - Fork 23
/
ft_strmapi.c
36 lines (32 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 15:32:15 by pbie #+# #+# */
/* Updated: 2015/12/02 23:49:18 by pbie ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*This function is exactly the same as ft_strmap except that when we run
* our given function f on the character we also pass to f the specific
* index of our character in the given string. Review ft_strmap in order
* to understand how this function works.*/
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *str;
i = 0;
str = (char *)malloc(sizeof(char) * (ft_strlen(s)) + 1);
if (str == NULL)
return (NULL);
while (s[i] != '\0')
{
str[i] = f(i, s[i]);
i++;
}
str[i] = '\0';
return (str);
}