71 lines
1.6 KiB
C
71 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_ultimate_range.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/06/16 16:26:42 by whaffman #+# #+# */
|
|
/* Updated: 2024/06/19 11:56:32 by whaffman ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
int ft_ultimate_range(int **range, int min, int max)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
if (min >= max)
|
|
{
|
|
*range = (void *) 0;
|
|
return (0);
|
|
}
|
|
*range = (int *) malloc((max - min) * sizeof(int));
|
|
if (!*range)
|
|
return (-1);
|
|
while (min < max)
|
|
{
|
|
(*range)[i] = min;
|
|
i++;
|
|
min++;
|
|
}
|
|
return (i);
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
void test(int min, int max)
|
|
{
|
|
int *range;
|
|
|
|
range = 0;
|
|
ft_ultimate_range(&range, min, max);
|
|
if (!range)
|
|
{
|
|
printf("NULL POINTER\n");
|
|
return ;
|
|
}
|
|
while (min < max)
|
|
{
|
|
printf("%d ", *range);
|
|
range++;
|
|
min++;
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
test(-3, 3);
|
|
test(0, 10);
|
|
test(-10, 2);
|
|
test(3, -3);
|
|
test(3, 3);
|
|
return (0);
|
|
}
|
|
|
|
#endif
|