42-archive/42-piscine-c/d10/ex02/ft_map.c
2016-08-25 20:50:28 +02:00

28 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/12 13:24:15 by jhalford #+# #+# */
/* Updated: 2016/08/12 13:24:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_map(int *tab, int length, int (*f)(int))
{
int i;
int *new_tab;
i = 0;
new_tab = malloc(sizeof(int) * (length + 1));
while (i < length)
{
new_tab[i] = f(tab[i]);
i++;
}
return (new_tab);
}