/ main.c
main.c
 1  /* ************************************************************************** */
 2  /*                                                                            */
 3  /*                                                        :::      ::::::::   */
 4  /*   main.c                                             :+:      :+:    :+:   */
 5  /*                                                    +:+ +:+         +:+     */
 6  /*   By: abonnard <abonnard@student.42nice.fr>      +#+  +:+       +#+        */
 7  /*                                                +#+#+#+#+#+   +#+           */
 8  /*   Created: 2024/07/20 14:01:17 by abonnard          #+#    #+#             */
 9  /*   Updated: 2024/07/20 16:18:29 by abonnard         ###   ########.fr       */
10  /*                                                                            */
11  /* ************************************************************************** */
12  
13  #include <unistd.h>
14  
15  int	my_scanf(char *size)
16  {
17  	int	i;
18  	int	answer;
19  
20  	answer = 0;
21  	i = 0;
22  	while (size[i] != '\0')
23  	{
24  		if (size[i] >= '0' && size[i] <= '9')
25  		{
26  			answer = answer * 10 + (size[i] - 48);
27  			i++;
28  		}
29  		else
30  		{
31  			return (-1);
32  		}
33  	}
34  	return (answer);
35  }
36  
37  int	main(int argc, char *argv[])
38  {
39  	int	lenght;
40  	int	height;
41  
42  	if (argc == 3)
43  	{
44  		lenght = my_scanf(argv[1]);
45  		height = my_scanf(argv[2]);
46  		if (height < 0 || lenght < 0)
47  		{
48  			write(1, "Parametres invalides", 20);
49  			return (0);
50  		}
51  		else
52  		{
53  			rush(height, lenght);
54  			return (0);
55  		}
56  	}
57  	else
58  	{
59  		write(1, "2 arguments sont attendu, height, lenght", 25);
60  	}
61  }