-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_0_inspect.c
70 lines (63 loc) · 2.06 KB
/
1_0_inspect.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 1_0_inspect.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anhigo-s <anhigo-s@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/16 23:03:27 by anhigo-s #+# #+# */
/* Updated: 2022/03/29 13:20:56 by anhigo-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "philosophers.h"
static int atoi_fchar(char *string);
static void print_arg_error(int index);
int inspect_args(int argc, char **argv)
{
int index;
index = 1;
if (argc == 5 || argc == 6)
{
while (index < argc)
{
if (atoi_fchar(argv[index]) < 1)
{
print_arg_error(index);
return (0);
}
index++;
}
return (1);
}
printf("philosophers: error wrong number of arguments\n");
return (0);
}
static int atoi_fchar(char *string)
{
int index;
index = 0;
while (string[index] != '\0')
{
if (inspect_char(string[index]))
{
return (-1);
}
index++;
}
return (ft_atoi(string));
}
static void print_arg_error(int index)
{
index--;
if (index == number_of_philosophers)
printf("philosophers: error in 'number of philosophers' argument\n");
else if (index == time_to_die)
printf("philosophers: error in 'time to die' argument\n");
else if (index == time_to_eat)
printf("philosophers: error in 'time to eat' argument\n");
else if (index == time_to_sleep)
printf("philosophers: error in 'time to sleep' argument\n");
else if (index == number_of_times_each_philosopher_must_eat)
printf("philosophers: error in optional argument: (%s)\n", OPTIONAL);
return ;
}