c fini bro
This commit is contained in:
parent
ea2251bed4
commit
32be727085
10
ft_atoi.c
10
ft_atoi.c
@ -6,17 +6,17 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/11/08 18:27:58 by cchauvet #+# #+# */
|
/* Created: 2022/11/08 18:27:58 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/12/02 21:39:08 by cchauvet ### ########.fr */
|
/* Updated: 2022/12/11 17:41:54 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "pushswap.h"
|
#include "pushswap.h"
|
||||||
|
|
||||||
int ft_atoi(char *str)
|
long int ft_atoi(char *str)
|
||||||
{
|
{
|
||||||
int nb;
|
long int nb;
|
||||||
int i;
|
int i;
|
||||||
int sign;
|
int sign;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
|
BIN
ft_bozo_sort.o
BIN
ft_bozo_sort.o
Binary file not shown.
BIN
ft_get_max.o
BIN
ft_get_max.o
Binary file not shown.
BIN
ft_is_sorted.o
BIN
ft_is_sorted.o
Binary file not shown.
18
ft_isnum.c
18
ft_isnum.c
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/11/08 18:43:06 by cchauvet #+# #+# */
|
/* Created: 2022/11/08 18:43:06 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/11/08 19:52:48 by cchauvet ### ########.fr */
|
/* Updated: 2022/12/11 17:49:49 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,10 +14,24 @@
|
|||||||
|
|
||||||
int ft_isnum(char *str)
|
int ft_isnum(char *str)
|
||||||
{
|
{
|
||||||
|
long int i;
|
||||||
|
int sign;
|
||||||
|
|
||||||
|
sign = 1;
|
||||||
|
if (*str == '-')
|
||||||
|
sign = -1;
|
||||||
|
i = 0;
|
||||||
|
if (*str == '-' || *str == '+')
|
||||||
|
str++;
|
||||||
|
if (*str == '\0')
|
||||||
|
return (0);
|
||||||
while (*str != '\0')
|
while (*str != '\0')
|
||||||
{
|
{
|
||||||
if (!((*str >= '0' && *str <= '9') || *str == '-' || *str == '+'))
|
if (i * sign > INT_MAX || INT_MIN > i * sign)
|
||||||
return (0);
|
return (0);
|
||||||
|
if (!(*str >= '0' && *str <= '9'))
|
||||||
|
return (0);
|
||||||
|
i = i * 10 + *str - '0';
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
|
BIN
ft_isnum.o
BIN
ft_isnum.o
Binary file not shown.
BIN
ft_putstr.o
BIN
ft_putstr.o
Binary file not shown.
BIN
ft_radix.o
BIN
ft_radix.o
Binary file not shown.
BIN
ft_split.o
BIN
ft_split.o
Binary file not shown.
BIN
ft_strlen.o
BIN
ft_strlen.o
Binary file not shown.
BIN
ft_tablen.o
BIN
ft_tablen.o
Binary file not shown.
17
main.c
17
main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/11/09 17:10:47 by cchauvet #+# #+# */
|
/* Created: 2022/11/09 17:10:47 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/12/11 15:48:20 by cchauvet ### ########.fr */
|
/* Updated: 2022/12/11 17:52:08 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ void ft_error(char **splitted)
|
|||||||
ft_cancel(splitted, len);
|
ft_cancel(splitted, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_parse(long int *tab, const char *s)
|
int ft_parse(long int *tab, const char *s, int index)
|
||||||
{
|
{
|
||||||
char **splitted;
|
char **splitted;
|
||||||
int i;
|
int i;
|
||||||
@ -45,21 +45,22 @@ int ft_parse(long int *tab, const char *s)
|
|||||||
splitted = ft_split(s, ' ');
|
splitted = ft_split(s, ' ');
|
||||||
if (splitted == NULL)
|
if (splitted == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
i = 0;
|
i = -1;
|
||||||
while (splitted[i] != NULL)
|
if (splitted[0] == NULL)
|
||||||
|
write(2, "Error\n", 6);
|
||||||
|
while (splitted[++i] != NULL)
|
||||||
{
|
{
|
||||||
if (!ft_isnum(splitted[i]))
|
if (!ft_isnum(splitted[i]))
|
||||||
{
|
{
|
||||||
ft_error(splitted);
|
ft_error(splitted);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
tab[i] = ft_atoi(splitted[i]);
|
tab[index + i] = ft_atoi(splitted[i]);
|
||||||
if (ft_isin(tab, i, tab[i]))
|
if (ft_isin(tab, index + i, tab[index + i]))
|
||||||
{
|
{
|
||||||
ft_error(splitted);
|
ft_error(splitted);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
ft_cancel(splitted, i + 1);
|
ft_cancel(splitted, i + 1);
|
||||||
return (i);
|
return (i);
|
||||||
@ -94,7 +95,7 @@ int main(int argc, char *argv[])
|
|||||||
len = 0;
|
len = 0;
|
||||||
while (++i < argc)
|
while (++i < argc)
|
||||||
{
|
{
|
||||||
y = ft_parse(tab_a + len, argv[i]);
|
y = ft_parse(tab_a, argv[i], (int) len);
|
||||||
if (y == 0)
|
if (y == 0)
|
||||||
{
|
{
|
||||||
free(tab_a);
|
free(tab_a);
|
||||||
|
43
pushswap.h
43
pushswap.h
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/11/08 18:19:44 by cchauvet #+# #+# */
|
/* Created: 2022/11/08 18:19:44 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/12/11 15:08:16 by cchauvet ### ########.fr */
|
/* Updated: 2022/12/11 17:55:38 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,36 +15,35 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
//# include <stdio.h>
|
|
||||||
# define STOP_VALUE 4294967295
|
# define STOP_VALUE 4294967295
|
||||||
|
|
||||||
int ft_isnum(char *str);
|
int ft_isnum(char *str);
|
||||||
size_t ft_strlen(const char *s);
|
size_t ft_strlen(const char *s);
|
||||||
int ft_atoi(char *str);
|
long int ft_atoi(char *str);
|
||||||
void ft_putstr(char *str);
|
void ft_putstr(char *str);
|
||||||
size_t ft_seglen(const char *s, char c);
|
size_t ft_seglen(const char *s, char c);
|
||||||
char **ft_split(const char *s, char c);
|
char **ft_split(const char *s, char c);
|
||||||
void ft_cancel(char **str, size_t len);
|
void ft_cancel(char **str, size_t len);
|
||||||
|
|
||||||
void ft_sort(long int *tab, int size);
|
void ft_sort(long int *tab, int size);
|
||||||
|
|
||||||
int ft_get_max_index(long int *tab, int size);
|
int ft_get_max_index(long int *tab, int size);
|
||||||
|
|
||||||
int ft_get_max(unsigned int *tab);
|
int ft_get_max(unsigned int *tab);
|
||||||
int ft_tablen(unsigned int *tab);
|
int ft_tablen(unsigned int *tab);
|
||||||
int ft_is_sorted(unsigned int *in);
|
int ft_is_sorted(unsigned int *in);
|
||||||
unsigned int ft_bitlen(unsigned int nb);
|
unsigned int ft_bitlen(unsigned int nb);
|
||||||
|
|
||||||
void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b);
|
void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b);
|
||||||
void ft_bozo_sort(unsigned int *tab_a, unsigned int *tab_b);
|
void ft_bozo_sort(unsigned int *tab_a, unsigned int *tab_b);
|
||||||
void ft_swap(unsigned int *a, unsigned int *b);
|
void ft_swap(unsigned int *a, unsigned int *b);
|
||||||
void ft_pa(unsigned int *tab_a, unsigned int *tab_b);
|
void ft_pa(unsigned int *tab_a, unsigned int *tab_b);
|
||||||
void ft_pb(unsigned int *tab_a, unsigned int *tab_b);
|
void ft_pb(unsigned int *tab_a, unsigned int *tab_b);
|
||||||
void ft_ra(unsigned int *tab_a);
|
void ft_ra(unsigned int *tab_a);
|
||||||
void ft_rb(unsigned int *tab_b);
|
void ft_rb(unsigned int *tab_b);
|
||||||
void ft_rra(unsigned int *tab_a);
|
void ft_rra(unsigned int *tab_a);
|
||||||
void ft_rrb(unsigned int *tab_b);
|
void ft_rrb(unsigned int *tab_b);
|
||||||
void ft_sa(unsigned int *tab_a);
|
void ft_sa(unsigned int *tab_a);
|
||||||
|
|
||||||
typedef unsigned int * t_tab;
|
typedef unsigned int *t_tab;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user