Argument handling
This commit is contained in:
parent
8fcb013229
commit
d05faa6679
75
main.c
75
main.c
|
@ -6,18 +6,79 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/18 02:09:32 by tischmid #+# #+# */
|
||||
/* Updated: 2023/03/18 02:51:40 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/03/18 03:50:10 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void rush(int x, int y);
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char *str);
|
||||
void ft_putnbr(int nb);
|
||||
int ft_atoi(char *str);
|
||||
|
||||
int main(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
rush(5, 3);
|
||||
rush(5, 1);
|
||||
rush(1, 1);
|
||||
rush(1, 5);
|
||||
rush(4, 4);
|
||||
int width;
|
||||
int height;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
ft_putstr("[31mWrong number of arguments (expected 2 got ");
|
||||
ft_putnbr(argc - 1);
|
||||
ft_putstr(")[m\n");
|
||||
return (1);
|
||||
}
|
||||
width = ft_atoi(argv[1]);
|
||||
height = ft_atoi(argv[2]);
|
||||
rush(width, height);
|
||||
// rush(5, 3);
|
||||
// rush(5, 1);
|
||||
// rush(1, 1);
|
||||
// rush(1, 5);
|
||||
// rush(4, 4);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
ft_putchar(str[i++]);
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char last_digit;
|
||||
|
||||
if (nb < 0)
|
||||
{
|
||||
ft_putchar('-');
|
||||
if (nb == 1 << 31)
|
||||
{
|
||||
nb += 2e9;
|
||||
ft_putchar('2');
|
||||
}
|
||||
nb *= -1;
|
||||
}
|
||||
last_digit = nb % 10 + '0';
|
||||
if (nb > 9)
|
||||
{
|
||||
nb /= 10;
|
||||
ft_putnbr(nb);
|
||||
}
|
||||
ft_putchar(last_digit);
|
||||
}
|
||||
|
||||
int ft_atoi(char *str)
|
||||
{
|
||||
int i;
|
||||
int number;
|
||||
|
||||
i = 0;
|
||||
number = 0;
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
number = number * 10 + (str[i++] - '0');
|
||||
return (number);
|
||||
}
|
||||
|
|
16
rush0X.c
16
rush0X.c
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rush00.c :+: :+: :+: */
|
||||
/* rush0X.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/18 02:10:24 by tischmid #+# #+# */
|
||||
/* Updated: 2023/03/18 03:02:19 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/03/18 03:47:34 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -17,9 +17,9 @@ const char g_inside = ' ';
|
|||
|
||||
// Rush 00
|
||||
// clockwise, starting from top left
|
||||
// const char g_corners[] = {'o', 'o', 'o', 'o'};
|
||||
// const char g_horizontal = '-';
|
||||
// const char g_vertical = '|';
|
||||
const char g_corners[] = {'o', 'o', 'o', 'o'};
|
||||
const char g_horizontal = '-';
|
||||
const char g_vertical = '|';
|
||||
|
||||
// Rush 01
|
||||
// const char g_corners[] = {'/', '\\', '/', '\\'};
|
||||
|
@ -37,9 +37,9 @@ const char g_inside = ' ';
|
|||
// const char g_vertical = 'B';
|
||||
|
||||
// Rush 04
|
||||
const char g_corners[] = {'A', 'C', 'A', 'C'};
|
||||
const char g_horizontal = 'B';
|
||||
const char g_vertical = 'B';
|
||||
// const char g_corners[] = {'A', 'C', 'A', 'C'};
|
||||
// const char g_horizontal = 'B';
|
||||
// const char g_vertical = 'B';
|
||||
|
||||
void rush(int x, int y)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue