Projet Fini
This commit is contained in:
parent
dd914622ed
commit
61a3861d39
9
Makefile
9
Makefile
|
@ -6,18 +6,16 @@
|
|||
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
|
||||
# Updated: 2022/12/02 19:24:34 by erey-bet ### ########.fr #
|
||||
# Updated: 2022/12/08 16:58:13 by erey-bet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
SRCS = push_swap.c operations.c tools.c parsing.c
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
CC = clang
|
||||
CFLAGS = -g -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
NAME = push_swap
|
||||
|
||||
# TU OUBLIS PAS LE -G DANS CFLAGS HEIN
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
|
@ -35,6 +33,8 @@ fclean: clean
|
|||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re coffee
|
||||
|
||||
coffee:
|
||||
@clear
|
||||
@echo ""
|
||||
|
@ -137,4 +137,3 @@ coffee:
|
|||
@echo ' """------"""'
|
||||
${MAKE} coffee
|
||||
|
||||
.PHONY: all clean fclean re coffee gdb
|
||||
|
|
51
parsing.c
51
parsing.c
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/07 19:23:59 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/12/07 19:24:04 by erey-bet ### ########.fr */
|
||||
/* Updated: 2022/12/08 11:22:53 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -25,6 +25,43 @@ void choice(long *tab, int y)
|
|||
write(1, "ra\n", 3);
|
||||
}
|
||||
|
||||
int put_error(void)
|
||||
{
|
||||
write(2, "Error\n", 6);
|
||||
return (1);
|
||||
}
|
||||
|
||||
char **set_only_space(char *argv[], int i)
|
||||
{
|
||||
int x;
|
||||
|
||||
x = 0;
|
||||
while (argv[i][x])
|
||||
if (ft_strchr("\a\b\t\n\v\f\r", argv[i][x++]) != NULL)
|
||||
argv[i][x - 1] = ' ';
|
||||
return (argv);
|
||||
}
|
||||
|
||||
int if_there_is_double(long *tab, int y)
|
||||
{
|
||||
int i;
|
||||
int x;
|
||||
|
||||
i = 0;
|
||||
while (i < y)
|
||||
{
|
||||
x = 0;
|
||||
while (x < y)
|
||||
{
|
||||
if (tab[i] == tab[x] && i != x)
|
||||
return (1);
|
||||
x++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int parsing(int argc, char *argv[], long *tab)
|
||||
{
|
||||
int i;
|
||||
|
@ -36,10 +73,7 @@ int parsing(int argc, char *argv[], long *tab)
|
|||
y = 0;
|
||||
while (++i < argc)
|
||||
{
|
||||
x = 0;
|
||||
while (argv[i][x])
|
||||
if (ft_strchr("\a\b\t\n\v\f\r", argv[i][x++]) != NULL)
|
||||
argv[i][x - 1] = ' ';
|
||||
argv = set_only_space(argv, i);
|
||||
x = 0;
|
||||
tmp = ft_split(argv[i], ' ');
|
||||
while (tmp[x] != NULL)
|
||||
|
@ -47,13 +81,12 @@ int parsing(int argc, char *argv[], long *tab)
|
|||
if (ft_atoi_check(tmp[x]))
|
||||
tab[y++] = ft_atoi(tmp[x]);
|
||||
else
|
||||
{
|
||||
write(1, "Error\n", 6);
|
||||
return (1);
|
||||
}
|
||||
return (put_error());
|
||||
x++;
|
||||
}
|
||||
}
|
||||
if (if_there_is_double(tab, y) || (y < argc - 1))
|
||||
return (put_error());
|
||||
choice(tab, y);
|
||||
return (0);
|
||||
}
|
||||
|
|
39
push_swap.c
39
push_swap.c
|
@ -6,49 +6,12 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/12/07 18:35:18 by erey-bet ### ########.fr */
|
||||
/* Updated: 2022/12/08 16:57:34 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
/*void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}*/
|
||||
|
||||
/*void print_stack(t_stack sa, t_stack sb)
|
||||
{
|
||||
write(1, "A: ", 3);
|
||||
for (int i = 0; i < sa.len; i++)
|
||||
{
|
||||
ft_putchar(sa.list[i] + '0');
|
||||
write(1, ", ", 2);
|
||||
}
|
||||
ft_putchar('\n');
|
||||
if (sb.len > 0)
|
||||
{
|
||||
write(1, "B: ", 3);
|
||||
for (int i = 0; i < sb.len; i++)
|
||||
{
|
||||
ft_putchar(sb.list[i] + '0');
|
||||
write(1, ", ", 2);
|
||||
}
|
||||
ft_putchar('\n');
|
||||
}
|
||||
}*/
|
||||
|
||||
/*void print_one_stack(t_stack s)
|
||||
{
|
||||
write(1, "A: ", 3);
|
||||
for (int i = 0; i < s.len; i++)
|
||||
{
|
||||
ft_putchar(s.list[i] + '0');
|
||||
write(1, ", ", 2);
|
||||
}
|
||||
ft_putchar('\n');
|
||||
}*/
|
||||
|
||||
void post_push_swap(t_stack sa, t_stack sb, int x, int sa_len)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/23 16:51:31 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/12/04 18:02:57 by erey-bet ### ########.fr */
|
||||
/* Updated: 2022/12/08 11:23:13 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
Loading…
Reference in a new issue