Compare commits
10 Commits
055739ffaf
...
562ea0fefb
| Author | SHA1 | Date |
|---|---|---|
|
|
562ea0fefb | |
|
|
22d33c9359 | |
|
|
608711320f | |
|
|
1b565f1938 | |
|
|
b5c71a6b2c | |
|
|
ca46c9f95e | |
|
|
d902e5d22b | |
|
|
f7675d98df | |
|
|
d05faa6679 | |
|
|
8fcb013229 |
|
|
@ -3,15 +3,16 @@
|
|||
/* ::: :::::::: */
|
||||
/* 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/19 04:21:28 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
// Display an ASCII char on standard output.
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
|
|
|
|||
68
main.c
68
main.c
|
|
@ -3,21 +3,71 @@
|
|||
/* ::: :::::::: */
|
||||
/* 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 02:51:40 by tischmid ### ########.fr */
|
||||
/* Created: 2023/03/18 20:15:26 by jtorrez- #+# #+# */
|
||||
/* Updated: 2023/03/19 04:22:13 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void rush(int x, int y);
|
||||
int ft_atoi(char *str);
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char *str);
|
||||
|
||||
int main(void)
|
||||
// entry point of the program
|
||||
// Parses the program arguments and fails if the number of passed
|
||||
// arguments is not 2.
|
||||
// Also fails if the passed arguments are out of
|
||||
// bounds (200 for width, 100 for height).
|
||||
// argv[0] contains the path of the executable, eg ./rush00
|
||||
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("Usage: ");
|
||||
ft_putstr(argv[0]);
|
||||
ft_putstr(" [width] [height]\n");
|
||||
return (1);
|
||||
}
|
||||
width = ft_atoi(argv[1]);
|
||||
height = ft_atoi(argv[2]);
|
||||
if (width >= 200)
|
||||
{
|
||||
ft_putstr("Width must be less than 200\n");
|
||||
return (2);
|
||||
}
|
||||
if (height >= 100)
|
||||
{
|
||||
ft_putstr("Height must be less than 100\n");
|
||||
return (3);
|
||||
}
|
||||
rush(width, height);
|
||||
return (0);
|
||||
}
|
||||
|
||||
// Convert a string to an integer
|
||||
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);
|
||||
}
|
||||
|
||||
// Display a null-terminated string on standard output.
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
ft_putchar(str[i++]);
|
||||
}
|
||||
|
|
|
|||
46
rush00.c
46
rush00.c
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* 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 03:02:19 by tischmid ### ########.fr */
|
||||
/* Created: 2023/03/18 20:15:12 by jtorrez- #+# #+# */
|
||||
/* Updated: 2023/03/19 04:21:23 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,37 +15,24 @@ void horiz_line(char left, char middle, char right, int width);
|
|||
|
||||
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 = '|';
|
||||
|
||||
// Rush 01
|
||||
// const char g_corners[] = {'/', '\\', '/', '\\'};
|
||||
// const char g_horizontal = '*';
|
||||
// const char g_vertical = '*';
|
||||
|
||||
// Rush 02
|
||||
// const char g_corners[] = {'A', 'A', 'C', 'C'};
|
||||
// const char g_horizontal = 'B';
|
||||
// const char g_vertical = 'B';
|
||||
|
||||
// Rush 03
|
||||
// const char g_corners[] = {'A', 'C', 'C', 'A'};
|
||||
// const char g_horizontal = 'B';
|
||||
// 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';
|
||||
// corners specified clockwise, starting from top left
|
||||
const char g_corners[] = {'o', 'o', 'o', 'o', '\0'};
|
||||
const char g_horizontal = '-';
|
||||
const char g_vertical = '|';
|
||||
|
||||
// Display a rectangle on standard output, specified by a width (x),
|
||||
// a height (y), a char array (g_corners) that contains the corners
|
||||
// in clockwise direction (starting from the top left), a char that
|
||||
// contains the horizontal character (g_horizontal), a char that contains
|
||||
// the vertical character (g_vertical), and additionally a char that
|
||||
// contains the inside ("the filling") character of the rectangle.
|
||||
void rush(int x, int y)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
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);
|
||||
|
|
@ -53,6 +40,9 @@ void rush(int x, int y)
|
|||
horiz_line(g_corners[3], g_horizontal, g_corners[2], x);
|
||||
}
|
||||
|
||||
// Display a horizontal line on standard output, specified by a single
|
||||
// left char, (width - 2) middle chars, and a single right char,
|
||||
// followed by a newline at the end.
|
||||
void horiz_line(char left, char middle, char right, int width)
|
||||
{
|
||||
int i;
|
||||
|
|
|
|||
Loading…
Reference in New Issue