Skip to content

Commit

Permalink
working on atoi
Browse files Browse the repository at this point in the history
  • Loading branch information
SaladBunda committed Apr 6, 2024
1 parent b55b46c commit a58e0fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
62 changes: 31 additions & 31 deletions srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/01 16:58:38 by ael-maaz #+# #+# */
/* Updated: 2024/04/06 02:10:03 by ael-maaz ### ########.fr */
/* Updated: 2024/04/06 02:53:07 by ael-maaz ### ########.fr */
/* */
/* ************************************************************************** */

#include "push_swap.h"

int test_argv(char **argv, int argc)
{
int i;
int j;
// int test_argv(char **argv, int argc)
// {
// int i;
// int j;

i = 1;
while (i < argc)
{
j = 0;
while (argv[i][j])
{
if ((argv[i][j] < '0' || argv[i][j] > '9')
&& argv[i][j] != ' ' && argv[i][j] != '-')
return (0);
j++;
}
i++;
}
return (1);
}
// i = 1;
// while (i < argc)
// {
// j = 0;
// while (argv[i][j])
// {
// if ((argv[i][j] < '0' || argv[i][j] > '9')
// && argv[i][j] != ' ' && argv[i][j] != '-')
// return (0);
// j++;
// }
// i++;
// }
// return (1);
// }

void fill_stack(char **av, int ac, t_stack *stack_a)
void fill_stack(char **av, int ac, t_stack *stack_a, int i)
{
int i;
int j;
int k;
char **arg;
int error;

error = 0;
k = stack_a->size - 1;
i = 0;
stack_a->top = -1;
while (++i < ac)
{
Expand All @@ -50,7 +50,7 @@ void fill_stack(char **av, int ac, t_stack *stack_a)
while (arg[++j])
{
stack_a->top++;
stack_a->stack[k--] = ft_atoi(arg[j]);
stack_a->stack[k--] = ft_atoi(arg[j], &error);
}
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ void init_stacks(char **av, int ac, t_stack *stack_a, t_stack *stack_b)
stack_b->size = stack_a->size;
stack_b->stack = malloc(sizeof(int) * stack_b->size);
stack_b->top = -1;
fill_stack(av, ac, stack_a);
fill_stack(av, ac, stack_a, 0);
return ;
}

Expand All @@ -115,17 +115,17 @@ int main(int ac, char **av)

if (ac > 1)
{
if (test_argv(av, ac) == 1)
{
// if (test_argv(av, ac) == 1)
// {
init_stacks(av, ac, &a, &b);
if (duplicates(a) == 0)
return (write(2, "Error\n", 6), 0);
if (is_sorted(&a) == 0)
return (0);
bubble_sort(&a);
range(&a, &b);
}
else
write(2, "Error\n", 6);
// range(&a, &b);
// }
// else
// write(2, "Error\n", 6);
}
}
4 changes: 2 additions & 2 deletions srcs/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/01 16:59:48 by ael-maaz #+# #+# */
/* Updated: 2024/04/05 23:04:17 by ael-maaz ### ########.fr */
/* Updated: 2024/04/06 02:53:04 by ael-maaz ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -45,7 +45,7 @@ void sort_five(t_stack *a, t_stack *b);
void sort_four(t_stack *a, t_stack *b);
int ft_strlen(char *s);
char **ft_split(char const *s, char c);
int ft_atoi(const char *s);
int ft_atoi(const char *s, int *error);
int is_sorted(t_stack *a);
int get_max_index(t_stack *b);

Expand Down
4 changes: 2 additions & 2 deletions srcs/util_func2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 22:26:52 by ael-maaz #+# #+# */
/* Updated: 2024/04/05 22:54:45 by ael-maaz ### ########.fr */
/* Updated: 2024/04/06 02:53:10 by ael-maaz ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -24,7 +24,7 @@ int ft_strlen(char *s)
return (count);
}

int ft_atoi(const char *s)
int ft_atoi(const char *s, int *error)
{
int i;
int sign;
Expand Down

0 comments on commit a58e0fa

Please sign in to comment.