42/d10/ex02/ft_map.c

29 lines
1.1 KiB
C
Raw Permalink Normal View History

2016-11-20 02:20:23 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 16:54:39 by gtertysh #+# #+# */
/* Updated: 2016/11/07 17:25:19 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_map(int *tab, int length, int (*f)(int))
{
int *arr;
int i;
i = 0;
arr = (int *)malloc(sizeof(int) * (length));
while (i < length)
{
arr[i] = f(tab[i]);
i++;
}
return (arr);
}