42_EXAM icon indicating copy to clipboard operation
42_EXAM copied to clipboard

ft_range result

Open aoshi2025s opened this issue 9 months ago • 0 comments

I submitted and failed. When I compiled and executed my ft_range.c, the program printed correctly.

----------------8<-------------[ START TEST
        💻 TEST
./a.out "1" "3"         🔎 YOUR OUTPUT:
        🗝 EXPECTED OUTPUT:
1$
2$
3$
----------------8<------------- END TEST ]

my code is:

#include <stdlib.h>

void swap(int *a, int *b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

int *ft_range(int start, int end)
{
	size_t	range;
	size_t	i;
	int		*result;

	if (!result)
		return (NULL);
	i = 0;
	if (start > end)
		swap(&start, &end);
	result = (int *)malloc(sizeof(int) * (range + 1));
	range = (end - start) + 1;
	while (start <= end)
	{
		result[i] = start;
		start++;
		i++;
	}
	return (result);
}

aoshi2025s avatar May 27 '24 14:05 aoshi2025s