Add clarifying comments
This commit is contained in:
parent
22d33c9359
commit
562ea0fefb
|
@ -6,12 +6,13 @@
|
|||
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <unistd.h>
|
||||
|
||||
// Display an ASCII char on standard output.
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
|
|
36
main.c
36
main.c
|
@ -6,26 +6,50 @@
|
|||
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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++]);
|
||||
}
|
||||
|
|
11
rush00.c
11
rush00.c
|
@ -6,7 +6,7 @@
|
|||
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
|
Loading…
Reference in New Issue