如何从查找表中获取地址?

时间:2015-07-24 09:18:18

标签: c function-pointers lookup-tables

我有main.c struct和查找表。

现在我想将struct head的地址“发送”到另一个C文件并调用它。 如何从名为head的查找表中获取地址并将其用于其他C文件?

// all is in the same main.c
//int main is in my main.c
int main()
{
    init();
    searcher();
    return 0;
}


//Look up tables are in my main.c too

static ExTable head[] ={
    {"hugo" , c ,NULL},
    {"bernd" , d ,NULL},
    {"anna" , a ,NULL},
    {"\0"}
};

我只在这里添加exTable,因为所有其他(a-z)只有其他名称和子标记。

static ExTable a[] = {    
    {"Say" , c ,NULL},
    {"Show" , b ,NULL},

    {"\0"}
};

//my init ... 
//here i think i would set the adress from my head
void init()
{

}

// in my tester.h 
// is my struct and  a lot of funktiondeclarations
typedef struct Table
{
    char* name;
    struct Table* subtab;
    void (*pfn)(char*);
} ExTable;

在我的tester.c我有一个void findname(ExTable* table, char* input)和 这应该找到名字。这个方法对你来说是无内容的:)但它需要一个static Extable* table和一个char*

我会在tester.c

中的其他方法中使用Method
  //searcher is in my tester.c
    void searcher()
    {
        //....................
        // inputs is a char[]
        inputs[strlen(inputs)-1] = '\0';
        // in head should be the adress from the head Look Up Table
//head is only an exable , i dont have it in my program because i dont know who i became the adress from my header LUT in my main to my tester.c in my parameter. when i wrote header , it doesn't works
        findname(head, inputs);
    }

0 个答案:

没有答案