aboutsummaryrefslogtreecommitdiff
path: root/c11/ex01/ft_map.c
blob: 8c973e2a1005d7455d0c068c8b5d6fc8f6a0daeb (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_map.c                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <charles.cabergs@gmail.com>       +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/07/16 21:17:12 by cacharle          #+#    #+#             */
/*   Updated: 2019/07/18 11:00:42 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>

int	*ft_map(int *tab, int length, int (*f)(int))
{
	int	i;
	int *mapped;

	if ((mapped = (int*)malloc(sizeof(int) * length)) == NULL)
		return (NULL);
	i = 0;
	while (i < length)
	{
		mapped[i] = (*f)(tab[i]);
		i++;
	}
	return (mapped);
}