This repository has been archived on 2023-12-28. You can view files and clone it, but cannot push or open issues or pull requests.
c_piscine_rush_02/ex00/main.c

49 lines
1.5 KiB
C
Raw Permalink Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rush-02.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 21:01:21 by achubuko #+# #+# */
2023-12-03 19:36:55 +00:00
/* Updated: 2023/12/03 22:21:05 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
2023-12-03 19:36:55 +00:00
int invalid_arg_num(char *arg)
{
2023-12-03 19:36:55 +00:00
if (ft_str_is_numeric(arg) == 0)
2023-12-03 14:09:56 +00:00
{
2023-12-03 19:36:55 +00:00
write(1, "Argument #1 must be a number!\n", 29);
return (3);
2023-12-03 14:09:56 +00:00
}
2023-12-03 19:36:55 +00:00
else if (ft_str_is_numeric(arg) == -1)
2023-12-03 14:09:56 +00:00
{
2023-12-03 19:36:55 +00:00
write(1, "Argument #1 must be positive!\n", 29);
2023-12-03 14:09:56 +00:00
return (2);
}
else
2023-12-03 19:36:55 +00:00
return (0);
}
int main(int argc, char **argv)
{
int chk;
t_dict *d;
if (argc <= 1 || argc > 3)
2023-12-03 14:09:56 +00:00
{
2023-12-03 19:36:55 +00:00
write(1, "Error: program requires 1 or 2 arguments passed!\n", 49);
return (1);
2023-12-03 14:09:56 +00:00
}
2023-12-03 19:36:55 +00:00
d = dict_create_default("numbers.dict");
if (argc == 3)
dict_update(d, argv[2]);
chk = invalid_arg_num(argv[1]);
if (!chk)
print_digit_words(argv[1]);
else
return (chk);
}