42_push_swap/main.c

39 lines
1.2 KiB
C
Raw Normal View History

2022-11-23 15:44:27 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 17:10:47 by cchauvet #+# #+# */
2022-12-09 09:22:02 -05:00
/* Updated: 2022/12/09 15:00:05 by cchauvet ### ########.fr */
2022-11-23 15:44:27 -05:00
/* */
/* ************************************************************************** */
#include "pushswap.h"
int main(int argc, char *argv[])
{
2022-12-06 11:35:45 -05:00
int i;
long int *tab_a;
2022-11-23 15:44:27 -05:00
2022-12-06 11:35:45 -05:00
tab_a = malloc(argc * sizeof(long int));
2022-11-23 15:44:27 -05:00
if (tab_a == NULL)
return (1);
2022-11-29 08:06:22 -05:00
i = 1;
while (i < argc)
2022-11-23 15:44:27 -05:00
{
2022-11-29 08:06:22 -05:00
if (!ft_isnum(argv[i]))
2022-11-23 15:44:27 -05:00
{
2022-11-30 14:11:35 -05:00
write(2, "Error\n", 6);
2022-12-09 09:22:02 -05:00
free(tab_a);
2022-11-23 15:44:27 -05:00
return (1);
}
2022-11-29 08:06:22 -05:00
tab_a[i - 1] = ft_atoi(argv[i]);
2022-11-23 15:44:27 -05:00
i++;
}
2022-11-29 08:06:22 -05:00
if (argc > 2)
ft_sort(tab_a, i - 1);
2022-11-23 15:44:27 -05:00
return (0);
}