summaryrefslogtreecommitdiff
path: root/libft/ft_strmapi.c
blob: f7693255b1ad3325edaa7f2b167b0fb66daeb1f0 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_strmapi.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: kdx    <kdx   @student.42angouleme.fr      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/09/28 20:06:57 by kdx               #+#    #+#             */
/*   Updated: 2022/10/14 02:25:55 by kdx              ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"

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

	if (s == NULL || f == NULL)
		return (NULL);
	copy = ft_strdup(s);
	if (copy == NULL)
		return (NULL);
	i = 0;
	while (copy[i] != '\0')
	{
		copy[i] = f(i, copy[i]);
		i += 1;
	}
	return (copy);
}