mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 13:17:16 +01:00
Piscine42
This commit is contained in:
54
C07/ex02/ft_ultimate_range.c
Executable file
54
C07/ex02/ft_ultimate_range.c
Executable file
@@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/14 17:31:36 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/15 10:48:55 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int *ft_range(int min, int max)
|
||||
{
|
||||
int *tab;
|
||||
int i;
|
||||
|
||||
if (min >= max)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
tab = (int *) malloc(sizeof(int) * (max - min));
|
||||
if (tab == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i = 0;
|
||||
while (i < max - min)
|
||||
{
|
||||
tab[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
|
||||
int ft_ultimate_range(int **range, int min, int max)
|
||||
{
|
||||
if (min >= max)
|
||||
{
|
||||
*range = 0;
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
*range = ft_range(min, max);
|
||||
if (*range == 0)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
return (max - min);
|
||||
}
|
||||
Reference in New Issue
Block a user