summaryrefslogtreecommitdiffstats
path: root/libft/src/ft_strmapi.c
blob: 7a38ca9b767feca1f0400fdac9d1bf773e2c3ddb (plain)
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
/* ************************************************************************** */
/*                                                          LE - /            */
/*                                                              /             */
/*   ft_strmapi.c                                     .::    .:/ .      .::   */
/*                                                 +:+:+   +:    +:  +:+:+    */
/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */
/*                                                 #+#   #+    #+    #+#      */
/*   Created: 2019/10/13 05:57:35 by rbousset     #+#   ##    ##    #+#       */
/*   Updated: 2019/10/13 08:35:12 by rbousset    ###    #+. /#+    ###.fr     */
/*                                                         /                  */
/*                                                        /                   */
/* ************************************************************************** */

#include "libft.h"

char
	*ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
	unsigned int	i;
	char			*nstr;

	if (!s)
		return (NULL);
	i = 0;
	nstr = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char));
	if (!nstr)
		return (NULL);
	while (s[i])
	{
		nstr[i] = (*f)(i, s[i]);
		i++;
	}
	return (nstr);
}