add max int
This commit is contained in:
parent
5fdc221dd1
commit
31b280bf34
3
Makefile
3
Makefile
@ -6,12 +6,13 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/02/13 16:27:49 by apommier #+# #+# #
|
||||
# Updated: 2022/03/15 17:49:12 by apommier ### ########.fr #
|
||||
# Updated: 2022/03/19 00:16:31 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = philo
|
||||
SRCS = srcs/main.c\
|
||||
srcs/check_args.c\
|
||||
srcs/init.c\
|
||||
srcs/exit.c\
|
||||
srcs/philo.c\
|
||||
|
||||
63
srcs/check_args.c
Normal file
63
srcs/check_args.c
Normal file
@ -0,0 +1,63 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_args.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/19 00:05:55 by apommier #+# #+# */
|
||||
/* Updated: 2022/03/19 00:21:03 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "philosophers.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!s)
|
||||
return (0);
|
||||
while (s[i] != 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
int is_nbr(int nb_args, char **list)
|
||||
{
|
||||
int j;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
j = 1;
|
||||
while (nb_args - j)
|
||||
{
|
||||
if (ft_strlen(list[j]) > 10)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (list[j][i])
|
||||
{
|
||||
if (list[j][i] < '0' || list[j][i] > '9')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
if (ft_atoi(list[j]) > 2147483647)
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_arg(int argc, char **argv)
|
||||
{
|
||||
if (argc != 5 && argc != 6)
|
||||
return (1);
|
||||
if (!is_nbr(argc, argv))
|
||||
return (1);
|
||||
if (argv[1][0] == '0' || (argv[1][0] == '1' && !argv[1][1]))
|
||||
return (1);
|
||||
if (argc == 6 && argv[5][0] == '0')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
27
srcs/utils.c
27
srcs/utils.c
@ -57,33 +57,6 @@ void put_event(t_arg *data, int philo_id, char *event)
|
||||
pthread_mutex_unlock(&data->life_check);
|
||||
}
|
||||
|
||||
int check_arg(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
j = 0;
|
||||
i = 1;
|
||||
if (argc != 5 && argc != 6)
|
||||
return (1);
|
||||
while (argv[i])
|
||||
{
|
||||
j = 0;
|
||||
while (argv[i][j])
|
||||
{
|
||||
if (argv[i][j] > '9' || argv[i][j] < '0')
|
||||
return (1);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (argv[1][0] == '0' || (argv[1][0] == '1' && !argv[1][1]))
|
||||
return (1);
|
||||
if (argc == 6 && argv[5][0] == '0')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_philo_full(t_philo *philo, t_arg *data)
|
||||
{
|
||||
int nb_full;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user