-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b55b46c
commit a58e0fa
Showing
3 changed files
with
35 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
@@ -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); | ||
} | ||
} | ||
} | ||
|
@@ -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 ; | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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; | ||
|