首页 > 其他 > 详细

表驱动法一

时间:2020-05-01 22:12:45      阅读:53      评论:0      收藏:0      [点我收藏+]

                                               使用表就是组织数据,使用的结构体类型,里面可以放数据和函数指针,然后定义一定数量的数组,然后for循环遍历。

                                               

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include<stdlib.h>
#include <dos.h>
#include <conio.h>



typedef enum  _Event_Type
{
    connect_usb_event,
    disconnect_usb_event,
    update_samples_event
}Event_Type;

typedef struct _event_process
{
    Event_Type event;
    int(*event_process)(void* input, void* output);
}Event_Process;


static int  connect_usb(void* input, void* output)
{
    printf("connect_usb\n");

    return 0;
}

static int  disconnect_usb(void* input, void* output)
{
    printf("disconnect_usb\n");

    return 0;
}

static int  update_samples(void* input, void* output)
{
    printf("update_samples\n");

    return 0;
}



static Event_Process  event_process[] =
{
    {connect_usb_event,connect_usb},
    {disconnect_usb_event,disconnect_usb},
    {update_samples_event,update_samples},

};


static int Cur_Event = 0;

int main()
{
    int i = 0;

    for (i = 0; i<sizeof(event_process)/sizeof(Event_Process); i++)
    {    
        if (Cur_Event == event_process[i].event)
        {
            ((event_process[i].event_process))(NULL, NULL);
        }
    }

    getchar();

    return 0;
}

技术分享图片

表驱动法一

原文:https://www.cnblogs.com/nowroot/p/12814898.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!