Compare commits

...

5 Commits

Author SHA1 Message Date
Juan Bosco Torrez Castillo 22d33c9359 header 2023-03-18 20:27:20 +01:00
Juan Bosco Torrez Castillo 608711320f Nicer early return for return in rush 2023-03-18 20:26:55 +01:00
Juan Bosco Torrez Castillo 1b565f1938 Better comment 2023-03-18 20:25:12 +01:00
Juan Bosco Torrez Castillo b5c71a6b2c Production ready 2023-03-18 20:24:08 +01:00
Juan Bosco Torrez Castillo ca46c9f95e Improved rush function 2023-03-18 19:49:02 +01:00
3 changed files with 16 additions and 79 deletions

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 02:10:16 by tischmid #+# #+# */
/* Updated: 2023/03/18 02:10:20 by tischmid ### ########.fr */
/* Created: 2023/03/18 20:27:12 by jtorrez- #+# #+# */
/* Updated: 2023/03/18 20:27:13 by jtorrez- ### ########.fr */
/* */
/* ************************************************************************** */

47
main.c
View File

@ -3,17 +3,14 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 02:09:32 by tischmid #+# #+# */
/* Updated: 2023/03/18 04:52:15 by tischmid ### ########.fr */
/* Created: 2023/03/18 20:15:26 by jtorrez- #+# #+# */
/* Updated: 2023/03/18 20:21:42 by jtorrez- ### ########.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(int argc, char *argv[])
@ -22,51 +19,13 @@ int main(int argc, char *argv[])
int height;
if (argc != 3)
{
ft_putstr("\033[31mWrong number of arguments (expected 2 got ");
ft_putnbr(argc - 1);
ft_putstr(")\033[m\n");
ft_putstr("\033[32mUsage: ./rush00 [width] [height]\033[m\n");
return (1);
}
width = ft_atoi(argv[1]);
height = ft_atoi(argv[2]);
rush(width, height);
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;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rush0X.c :+: :+: :+: */
/* rush00.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 02:10:24 by tischmid #+# #+# */
/* Updated: 2023/03/18 05:01:27 by tischmid ### ########.fr */
/* Created: 2023/03/18 20:15:12 by jtorrez- #+# #+# */
/* Updated: 2023/03/18 20:26:32 by jtorrez- ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,39 +15,19 @@ void horiz_line(char left, char middle, char right, int width);
const char g_inside = ' ';
// Rush 00
// clockwise, starting from top left
// corners specified clockwise, starting from top left
const char g_corners[] = {'o', 'o', 'o', 'o', '\0'};
const char g_horizontal = '-';
const char g_vertical = '|';
// Rush 01
// const char g_corners[] = {'/', '\\', '/', '\\', '\0'};
// const char g_horizontal = '*';
// const char g_vertical = '*';
// Rush 02
// const char g_corners[] = {'A', 'A', 'C', 'C', '\0'};
// const char g_horizontal = 'B';
// const char g_vertical = 'B';
// Rush 03
// const char g_corners[] = {'A', 'C', 'C', 'A', '\0'};
// const char g_horizontal = 'B';
// const char g_vertical = 'B';
// Rush 04
// const char g_corners[] = {'A', 'C', 'A', 'C', '\0'};
// const char g_horizontal = 'B';
// const char g_vertical = 'B';
void rush(int x, int y)
{
int i;
i = 0;
if (y)
horiz_line(g_corners[0], g_horizontal, g_corners[1], x);
if (x * y == 0)
return ;
horiz_line(g_corners[0], g_horizontal, g_corners[1], x);
while (i++ < y - 2)
horiz_line(g_vertical, g_inside, g_vertical, x);
if (y > 1)
@ -59,12 +39,10 @@ void horiz_line(char left, char middle, char right, int width)
int i;
i = 0;
if (width)
ft_putchar(left);
ft_putchar(left);
while (i++ < width - 2)
ft_putchar(middle);
if (width > 1)
ft_putchar(right);
if (width)
ft_putchar('\n');
ft_putchar('\n');
}