first commit
This commit is contained in:
37
ended/C07/ex02/ft_ultimate_range.c
Normal file
37
ended/C07/ex02/ft_ultimate_range.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 21:00:29 by ajoly #+# #+# */
|
||||
/* Updated: 2022/08/03 14:55:34 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_ultimate_range(int **range, int min, int max)
|
||||
{
|
||||
int i;
|
||||
int *result;
|
||||
int diff;
|
||||
|
||||
diff = max - min;
|
||||
result = malloc((diff + 1) * sizeof(int));
|
||||
i = 0;
|
||||
if (min >= max)
|
||||
{
|
||||
*range = NULL;
|
||||
return (0);
|
||||
}
|
||||
while (min < max)
|
||||
{
|
||||
result[i] = min;
|
||||
i++;
|
||||
min++;
|
||||
}
|
||||
*range = result;
|
||||
return (i);
|
||||
}
|
Reference in New Issue
Block a user