- 论坛徽章:
- 0
|
1 #include<stdio.h>
2
3 void func1(void){printf("called func1!\n");}
4 void func2(void){printf("called func2!\n");}
5 void func3(void){printf("called func3!\n");}
6 void func4(void){printf("called func4!\n");}
7 void func5(void){printf("called func5!\n");}
8
9 typedef void (*FUNC)();
10
11 FUNC funs[5]={func5,func4,func3,func2,func1};
12
13 void test_nu(int num)
14 {
15 int i,j=0;
16 int mask=0x1;//用来判断那一位上信号是否为1
17 int x;
18 for(i=1;i<=5;i++){
19 x = num & mask;
20 mask <<= 1;
21 if(i>2)
22 {
23 if(x) j=i;
24 }
25 else if(x) (*funs[i-1])();
26 }
27 if(j!=0) (*funs[j-1])();
28 }
29
30 int main(int argc,char **argv)
31 {
32 int num;
33 for(num =0; num < 32;num++){
34 printf("num = %d\n",num);
35 test_nu(num);
36 printf("\n\n");
37 }
38 return 0;
39 }
稍微改了一下后的程序 |
|