diff --git a/ft_putchar.c b/ft_putchar.c index 16f7bf8..de49b7c 100644 --- a/ft_putchar.c +++ b/ft_putchar.c @@ -6,12 +6,13 @@ /* By: jtorrez- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/18 20:27:12 by jtorrez- #+# #+# */ -/* Updated: 2023/03/18 20:27:13 by jtorrez- ### ########.fr */ +/* Updated: 2023/03/19 04:21:28 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include +// Display an ASCII char on standard output. void ft_putchar(char c) { write(1, &c, 1); diff --git a/main.c b/main.c index fa55b48..366f400 100644 --- a/main.c +++ b/main.c @@ -6,26 +6,50 @@ /* By: jtorrez- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/18 20:15:26 by jtorrez- #+# #+# */ -/* Updated: 2023/03/18 20:21:42 by jtorrez- ### ########.fr */ +/* 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); +// 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[]) { 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; @@ -37,3 +61,13 @@ int ft_atoi(char *str) 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++]); +} diff --git a/rush00 b/rush00 new file mode 100755 index 0000000..b0d4001 Binary files /dev/null and b/rush00 differ diff --git a/rush00.c b/rush00.c index 41b6d2e..bdaedd7 100644 --- a/rush00.c +++ b/rush00.c @@ -6,7 +6,7 @@ /* By: jtorrez- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/18 20:15:12 by jtorrez- #+# #+# */ -/* Updated: 2023/03/18 20:26:32 by jtorrez- ### ########.fr */ +/* Updated: 2023/03/19 04:21:23 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,12 @@ 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; @@ -34,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;