Compare commits

...

5 Commits

Author SHA1 Message Date
Timo Schmidt 22ca98299b Handle negative numbers in rush00.c 2023-03-19 19:08:45 +01:00
Timo Schmidt 4053efeaef Handle negative numbers for error message 2023-03-19 19:08:22 +01:00
Timo Schmidt 830f860e02 Return on wrong argc 2023-03-19 18:21:09 +01:00
Timo Schmidt 686c98f607 Idk 2023-03-19 18:11:30 +01:00
Timo Schmidt 6b9b87010d Idk 2023-03-19 18:11:19 +01:00
3 changed files with 21 additions and 15 deletions

View File

@ -6,7 +6,7 @@
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 20:15:26 by jtorrez- #+# #+# */
/* Updated: 2023/03/19 17:20:41 by tischmid ### ########.fr */
/* Updated: 2023/03/19 19:07:32 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,48 +19,54 @@ void ft_putstr(char *str);
// Parses the program arguments and fails if the number of passed
// arguments is not 2 or 0.
// Also fails if the passed arguments are out of
// bounds (200 for width, 100 for height).
// bounds (0-200 for width, 0-100 for height).
// argv[0] contains the path of the executable, eg ./rush00
#include <stdio.h>
int main(int argc, char *argv[])
{
int width;
int height;
width = 10;
height = 5;
if (argc != 1 && argc != 3)
{
ft_putstr("Usage: ");
ft_putstr(argv[0]);
ft_putstr(" [WIDTH HEIGHT]\n");
return (1);
}
if (argc == 1)
if (argc == 3)
{
width = ft_atoi(argv[1]);
height = ft_atoi(argv[2]);
}
else
width = 5;
height = 3;
if (width >= 200)
ft_putstr("Width must be less than 200\n");
else if (height >= 100)
ft_putstr("Height must be less than 100\n");
if (width < 0 || width > 200)
ft_putstr("Width must be in the range of 0 to 200\n");
else if (height < 0 || height > 100)
ft_putstr("Height must be in the range of 0 to 100\n");
else
rush(width, height);
return (0);
}
// Convert a string to an integer
// Convert a string to a non-zero integer
int ft_atoi(char *str)
{
int i;
int sign;
int number;
i = 0;
number = 0;
sign = 1;
if (str[i] == '-')
{
sign = -1;
++i;
}
while (str[i] >= '0' && str[i] <= '9')
number = number * 10 + (str[i++] - '0');
return (number);
return (sign * number);
}
// Display a null-terminated string on standard output.

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: jtorrez- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 20:15:12 by jtorrez- #+# #+# */
/* Updated: 2023/03/19 04:21:23 by tischmid ### ########.fr */
/* Updated: 2023/03/19 18:56:58 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,7 +31,7 @@ void rush(int x, int y)
int i;
i = 0;
if (x * y == 0)
if (x < 1 && y < 1)
return ;
horiz_line(g_corners[0], g_horizontal, g_corners[1], x);
while (i++ < y - 2)