-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy path3-main.c
executable file
·49 lines (43 loc) · 984 Bytes
/
3-main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdlib.h>
#include <stdio.h>
#include "3-calc.h"
/**
* main - get_op_func has operators correlated with
* func signs and funcs from op_func
* if not 4 arguments, return Error & exit 98
* if op is null, return Error & exit 99
* if div or mod 0, return Error & exit 100
* run calc, input one, operator, input two = pointer res to get_op
* @argc: arguments
* @argv: double pointer to arguments
* Return: 0
*/
int main(int argc, char *argv[])
{
int one, two, ans;
int (*res)(int, int);
char *get_op;
if (argc != 4)
{
printf("Error\n");
exit(98);
}
one = atoi(argv[1]);
two = atoi(argv[3]);
get_op = argv[2];
/* added edge case if argv[2] was longer than 1 char*/
if (get_op_func(argv[2]) == NULL || argv[2][1] != '\0')
{
printf("Error\n");
exit(99);
}
if ((*get_op == '/' || *get_op == '%') && (*argv[3] == '0'))
{
printf("Error\n");
exit(100);
}
res = get_op_func(get_op);
ans = res(one, two);
printf("%d\n", ans);
return (0);
}