piscine/c07/ex01/ft_range.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

65 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/16 15:57:44 by whaffman #+# #+# */
/* Updated: 2024/06/17 10:13:54 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <stdio.h>
int *ft_range(int min, int max)
{
int *res;
int *ores;
if (min >= max)
return ((void *) 0);
res = (int *) malloc((max - min) * sizeof(int));
ores = res;
while (min < max)
{
*res = min;
res++;
min++;
}
return (ores);
}
#ifdef DEBUG
void test(int min, int max)
{
int *range;
range = ft_range(min, max);
if (!range)
{
printf("NULL POINTER\n");
return ;
}
while (min < max)
{
printf("%d ", *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