first commit
This commit is contained in:
39
C07/ex02/ft_ultimate_range.c
Normal file
39
C07/ex02/ft_ultimate_range.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/27 19:51:50 by adjoly #+# #+# */
|
||||
/* Updated: 2023/08/03 20:25:00 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_ultimate_range(int **range, int min, int max)
|
||||
{
|
||||
int i;
|
||||
int *arr;
|
||||
|
||||
i = 0;
|
||||
if (min >= max)
|
||||
{
|
||||
*range = 0;
|
||||
return (0);
|
||||
}
|
||||
arr = malloc((max - min) * sizeof(int));
|
||||
if (arr == NULL)
|
||||
{
|
||||
*range = 0;
|
||||
return (-1);
|
||||
}
|
||||
while (min < max)
|
||||
{
|
||||
arr[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
*range = arr;
|
||||
return (max - min);
|
||||
}
|
Reference in New Issue
Block a user