C中结构体数组的使用

在.h中

typedef struct value_channel

{

unsigned char dir;

unsigned int ADCValue[128];

}v_c;

extern v_c value[4];

在.c中

v_c value[4];

函数指针

void ( * fp)(void);

void fun_start_01(void);

{

......

}

void fun_start(void)

{

switch(cs)

{    

    case 01:

        fp=fun_start_01;

    break;

}

}

( * fp)();

函数地址

typedef void( * dis_turn)(void);

void dis_turn_1(void)

void dis_turn_2(void)

dis_turn dis[]={dis_turn_1,dis_turn_2};

main()

{

dis[0]();

dis[1]();

}

实现菜单

typedef void(*FUN_P)(void);//(int Data) typedef struct Message_Item { unsigned char cStatus; FUN_P fnProcess; }MSG_ITEM;

MSG_ITEM MSGMap[]={{0x00,fun_start},{0x01,fun_normal},{0x02,fun_set0},{0x03,fun_gas},{0x04,fun_set}};

void SearchMSGMAP(void) //(unsigned char cStatus) { unsigned char n=0; for(n=0;n<UBOND(MSGMap);n++) { if(MSGMap[n].cStatus==(cs>>4)) //(cStatus>>4)) {

MSGMap[n].fnProcess();

}

}

}

标签: C

添加新评论