-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-main.c
More file actions
44 lines (37 loc) · 781 Bytes
/
Copy path3-main.c
File metadata and controls
44 lines (37 loc) · 781 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
41
42
43
44
#include <stdio.h> /* printf */
#include <stdlib.h> /* atoi */
#include "3-calc.h"
/**
* main - when user runs main,
* user should give two integers and an operator and
* main will calculate the math via a function pointer.
* prints sum, difference, product, dividend, or remainder
* @argc: argument counter
* @argv: arguments
* Return: 0 on sucess
*/
int main(int argc, char *argv[])
{
int n1, n2;
int (*f)(int, int);
if (argc != 4)
{
printf("Error\n");
exit(98);
}
n1 = atoi(argv[1]);
n2 = atoi(argv[3]);
f = get_op_func(argv[2]);
if (!f || argv[2][1] != '\0')
{
printf("Error\n");
exit(99);
}
if ((argv[2][0] == '/' || argv[2][0] == '%') && argv[3][0] == '0')
{
printf("Error\n");
exit(100);
}
printf("%d\n", f(n1, n2));
return (0);
}