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

56 lines
1.6 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]);
2023-12-07 16:06:51 +00:00
t_file *file = ft_open(argv[1]);
ft_buffer_line(file);
printf("%s\n", file->buffer);
2023-12-03 19:36:55 +00:00
if (!chk)
print_digit_words(argv[1]);
else
return (chk);
}