-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path3-main.c
More file actions
40 lines (33 loc) · 680 Bytes
/
3-main.c
File metadata and controls
40 lines (33 loc) · 680 Bytes
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
#include "3-calc.h"
#include <stdio.h>
#include <stdlib.h>
/**
* main - Prints calculator result
*
* @argc: int of commandline args
*
* @argv: 2-d array of commandline args
*
* Return: 0 success, 98 for argc error, 100 if div 0
*/
int main(int argc, char **argv)
{
int (*operator_function)(int, int), num1, num2;
if (argc != 4)
printf("Error\n"), exit(98);
num1 = atoi(argv[1]);
num2 = atoi(argv[3]);
operator_function = get_op_func(argv[2]);
if (!operator_function)
{
printf("Error\n");
exit(99);
}
if (!num2 && (argv[2][0] == '/' || argv[2][0] == '%'))
{
printf("Error\n");
exit(100);
}
printf("%d\n", operator_function(num1, num2));
return (0);
}