Compare commits
2 Commits
a31f44d552
...
f0bc88b8ec
Author | SHA1 | Date | |
---|---|---|---|
|
f0bc88b8ec | ||
|
a5c0814aa3 |
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* utils.c :+: :+: :+: */
|
/* ft_utils.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/02 21:56:30 by achubuko #+# #+# */
|
/* Created: 2023/12/02 21:56:30 by achubuko #+# #+# */
|
||||||
/* Updated: 2023/12/02 23:45:23 by achubuko ### ########.fr */
|
/* Updated: 2023/12/03 18:07:15 by achubuko ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "ft_utils.h"
|
#include "ft_utils.h"
|
||||||
@ -25,3 +25,21 @@ size_t ft_strlen(char *s)
|
|||||||
l++;
|
l++;
|
||||||
return (l);
|
return (l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ft_str_is_numeric(char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (str[i] == '\0')
|
||||||
|
return (0);
|
||||||
|
while (str[i] != '\0')
|
||||||
|
{
|
||||||
|
if (str[i] < '0' || str[i] > '9')
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (str[0] == '-')
|
||||||
|
return (-1);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/02 21:57:06 by achubuko #+# #+# */
|
/* Created: 2023/12/02 21:57:06 by achubuko #+# #+# */
|
||||||
/* Updated: 2023/12/02 23:04:09 by achubuko ### ########.fr */
|
/* Updated: 2023/12/03 18:08:38 by achubuko ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#ifndef FT_UTILS_H
|
#ifndef FT_UTILS_H
|
||||||
@ -16,4 +16,5 @@
|
|||||||
|
|
||||||
uint32_t ft_atoui32(char *str);
|
uint32_t ft_atoui32(char *str);
|
||||||
size_t ft_strlen(char *s);
|
size_t ft_strlen(char *s);
|
||||||
|
int ft_str_is_numeric(char *str);
|
||||||
#endif
|
#endif
|
||||||
|
17
ex00/main.c
17
ex00/main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/02 21:01:21 by achubuko #+# #+# */
|
/* Created: 2023/12/02 21:01:21 by achubuko #+# #+# */
|
||||||
/* Updated: 2023/12/02 23:45:57 by achubuko ### ########.fr */
|
/* Updated: 2023/12/03 18:09:34 by achubuko ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
@ -18,5 +18,18 @@ int main(int argc, char **argv)
|
|||||||
write(1, "Error: program requires 1 or 2 arguments passed!", 48);
|
write(1, "Error: program requires 1 or 2 arguments passed!", 48);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
write(1, argv[1], ft_strlen(argv[1]));
|
if (ft_str_is_numeric(argv[1]) == 1)
|
||||||
|
{
|
||||||
|
print_digit_words(argv[1]);
|
||||||
|
}
|
||||||
|
else if (ft_str_is_numeric(argv[1]) == -1)
|
||||||
|
{
|
||||||
|
write(1, "Argument #1 must be positive!", 28);
|
||||||
|
return (2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
write(1, "Argument #1 must be a number!", 28);
|
||||||
|
return (3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user