74 lines
2.0 KiB
C
74 lines
2.0 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* main.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jtorrez- <marvin@42.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);
|
|
|
|
// 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;
|
|
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++]);
|
|
}
|