ft_range.c 557 B

12345678910111213141516171819202122232425262728293031323334
  1. /* Create a function ft_range which returns an array ofints. This int array should
  2. contain all values between min and max.
  3. Min included - max excluded. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. int *ft_range(int min, int max)
  7. {
  8. int len, i;
  9. int * array;
  10. if (min >= max)
  11. return (0);
  12. len = max - min;
  13. i = 0;
  14. array = (int*)malloc(sizeof(int) * (len));
  15. if (array == NULL)
  16. return (NULL);
  17. while (len--)
  18. {
  19. array[i] = min + i;
  20. i++;
  21. }
  22. return (array);
  23. }
  24. int main(void)
  25. {
  26. printf("%d", ft_range(2, 5));
  27. return (0);
  28. }