diff options
Diffstat (limited to 'c11/ex05')
| -rw-r--r-- | c11/ex05/Makefile | 4 | ||||
| -rwxr-xr-x | c11/ex05/do-op | bin | 8956 -> 0 bytes | |||
| -rw-r--r-- | c11/ex05/helper.c | 6 | ||||
| -rw-r--r-- | c11/ex05/include.h | 6 | ||||
| -rw-r--r-- | c11/ex05/main.c | 11 | ||||
| -rw-r--r-- | c11/ex05/operators.c | 14 | ||||
| -rw-r--r-- | c11/ex05/parse.c | 26 |
7 files changed, 35 insertions, 32 deletions
diff --git a/c11/ex05/Makefile b/c11/ex05/Makefile index 0aca71b..ae0b6ad 100644 --- a/c11/ex05/Makefile +++ b/c11/ex05/Makefile @@ -6,13 +6,13 @@ # By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/07/17 07:55:23 by cacharle #+# #+# # -# Updated: 2019/07/17 08:15:25 by cacharle ### ########.fr # +# Updated: 2019/07/18 10:21:51 by cacharle ### ########.fr # # # # **************************************************************************** # OUT = do-op CC = gcc -FLAGS = -Wall -Wextra #-Werror +FLAGS = -Wall -Wextra -Werror SRC = main.c operators.c parse.c helper.c OBJ = $(SRC:.c=.o) diff --git a/c11/ex05/do-op b/c11/ex05/do-op Binary files differdeleted file mode 100755 index 90f13df..0000000 --- a/c11/ex05/do-op +++ /dev/null diff --git a/c11/ex05/helper.c b/c11/ex05/helper.c index 8f370de..57075dc 100644 --- a/c11/ex05/helper.c +++ b/c11/ex05/helper.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 07:53:07 by cacharle #+# #+# */ -/* Updated: 2019/07/17 07:53:59 by cacharle ### ########.fr */ +/* Updated: 2019/07/18 10:38:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ void ft_putnbr(int nb) ft_putchar(p_nb % 10 + '0'); } -int pow10(int exponent) +int pow10(int exponent) { int accumulator; @@ -46,7 +46,7 @@ int pow10(int exponent) return (accumulator); } -int ft_atoi(char *str) +int ft_atoi(char *str) { int is_negative; int nb; diff --git a/c11/ex05/include.h b/c11/ex05/include.h index 49381a3..bc92263 100644 --- a/c11/ex05/include.h +++ b/c11/ex05/include.h @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 07:38:10 by cacharle #+# #+# */ -/* Updated: 2019/07/17 08:15:39 by cacharle ### ########.fr */ +/* Updated: 2019/07/18 10:40:10 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,8 +27,8 @@ int modulo(int x, int y); ** parse.c */ -int parse(int argc, char **argv); -//int make_operation(int x, int y, int (*operator)(int, int)) +int parse(int argc, char **argv); +int check_floating_point_error(int operator_index, int y); /* ** helper.c diff --git a/c11/ex05/main.c b/c11/ex05/main.c index e234053..c29b6ef 100644 --- a/c11/ex05/main.c +++ b/c11/ex05/main.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 07:29:52 by cacharle #+# #+# */ -/* Updated: 2019/07/17 16:37:31 by cacharle ### ########.fr */ +/* Updated: 2019/07/18 10:38:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,13 +34,8 @@ int main(int argc, char **argv) { x = ft_atoi(argv[1]); y = ft_atoi(argv[3]); - if (operator_index == 3 && y == 0) - { - - } - if (operator_index == 3 && y == 0) - { - } + if (check_floating_point_error(operator_index, y) == -1) + return (0); ft_putnbr((*operators[operator_index])(x, y)); } ft_putchar('\n'); diff --git a/c11/ex05/operators.c b/c11/ex05/operators.c index c138be3..4efba28 100644 --- a/c11/ex05/operators.c +++ b/c11/ex05/operators.c @@ -6,33 +6,31 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 07:38:59 by cacharle #+# #+# */ -/* Updated: 2019/07/17 08:03:34 by cacharle ### ########.fr */ +/* Updated: 2019/07/18 10:38:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -int add(int x, int y) +int add(int x, int y) { return (x + y); } -int subtract(int x, int y) +int subtract(int x, int y) { - return (x - y); } -int multiply(int x, int y) +int multiply(int x, int y) { - return (x * y); } -int divide(int x, int y) +int divide(int x, int y) { return (x / y); } -int modulo(int x, int y) +int modulo(int x, int y) { return (x % y); } diff --git a/c11/ex05/parse.c b/c11/ex05/parse.c index 5b1c531..1540945 100644 --- a/c11/ex05/parse.c +++ b/c11/ex05/parse.c @@ -6,10 +6,12 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 08:05:59 by cacharle #+# #+# */ -/* Updated: 2019/07/17 08:35:50 by cacharle ### ########.fr */ +/* Updated: 2019/07/18 10:40:34 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ +#include <unistd.h> + int parse(int argc, char **argv) { int i; @@ -27,13 +29,21 @@ int parse(int argc, char **argv) else if (argv[2][0] == '%') i = 4; else - i = -2; + i = -2; return (i); } -/*int make_operation(int x, int y, int (*operator)(int, int))*/ -/*{*/ - - /*retu*/ - -/*}*/ +int check_floating_point_error(int operator_index, int y) +{ + if (operator_index == 3 && y == 0) + { + write(1, "Stop : division by zero\n", 24); + return (-1); + } + if (operator_index == 4 && y == 0) + { + write(1, "Stop : modulo by zero\n", 22); + return (-1); + } + return (0); +} |
