aboutsummaryrefslogtreecommitdiff
path: root/c11/ex05
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-19 07:04:04 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-19 07:04:04 +0200
commit8b6e91bdb56bc01a588718472546f2a88e750b48 (patch)
tree654ba9e8216c688bb3d6a2e5d67526ae8ec4b874 /c11/ex05
parent880102ae9358db130ef67cc9a7177a1e1de76875 (diff)
downloadpiscine-8b6e91bdb56bc01a588718472546f2a88e750b48.tar.gz
piscine-8b6e91bdb56bc01a588718472546f2a88e750b48.tar.bz2
piscine-8b6e91bdb56bc01a588718472546f2a88e750b48.zip
c10 done?, c11 moulinetted (ex04, ex06 need correction)
Diffstat (limited to 'c11/ex05')
-rw-r--r--c11/ex05/Makefile4
-rwxr-xr-xc11/ex05/do-opbin8956 -> 0 bytes
-rw-r--r--c11/ex05/helper.c6
-rw-r--r--c11/ex05/include.h6
-rw-r--r--c11/ex05/main.c11
-rw-r--r--c11/ex05/operators.c14
-rw-r--r--c11/ex05/parse.c26
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
deleted file mode 100755
index 90f13df..0000000
--- a/c11/ex05/do-op
+++ /dev/null
Binary files differ
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);
+}