push_swap/tools_2.c
2022-12-11 15:58:47 +01:00

60 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 15:54:00 by erey-bet #+# #+# */
/* Updated: 2022/12/11 15:51:37 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
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);
}
void *init_sb(t_stack *sb, int len)
{
sb->list = malloc(sizeof(long) * (len + 1));
if (sb->list == NULL)
return (NULL);
sb->len = 0;
return (sb);
}