-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_11_28_2.c
More file actions
71 lines (62 loc) · 1.22 KB
/
test_11_28_2.c
File metadata and controls
71 lines (62 loc) · 1.22 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int add(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}
int mul(int a, int b)
{
return a * b;
}
int mydiv(int a, int b)
{
if(b == 0){
printf("your proc is diving zero!!\n");
return -1;
}
return a / b;
}
int quit(int a, int b)
{
printf("Bye~~\n");
exit(0);
}
int help(int a, int b)
{
printf("Usage: use option [0, 1, 2, 3, 4, 5]\n");
return 0;
}
int main()
{
// int (*p[6])(int,int) = {help, add, sub, mul, mydiv, quit};
int (*p[6])(int,int);
int (*(*q)[6])(int, int);
q = &p;
printf("%p, %p\n", q, q+1);
p[0]=&help;
while(1){
printf("########################################\n");
printf("### 1. add ################# 2. sub ####\n");
printf("### 3. mul ################# 4. div ####\n");
printf("### 5. quit ################ 0. help ###\n");
printf("########################################\n");
int s = 0;
printf("Please Select<0~5>: ");
scanf("%d", &s);
if( s < 0 || s > 5 ){
s = 5;
}
int x, y;
if( s != 0 && s != 5 ){
printf("Please Enter Your data<x, y>: ");
scanf("%d%d", &x, &y);
}
printf("result> %d\n", p[s](x, y));
}
return 0;
}