无法编译哈希表ADT - C.

时间:2012-05-01 22:35:37

标签: c hash

我一直收到错误:

  1. 赋值使用指针生成整数而不使用强制转换
  2. 尝试使用以下命令编译我的哈希表ADT时:

    gcc hash_NEW.c -c
    

    在1个函数中遇到错误较大的.c文件。 感谢您的帮助

    错误1出现在此处(index = table-> hash_func;)

    void insert_hash(Phash_table table, char *key, void *data){
        Phash_entry new;   //pointer to a new node of type hash_entry
        int index;
    
        new = (Phash_entry)malloc(sizeof(hash_entry));
        new->key = (char *)malloc(sizeof(char)*strlen(key));  //creates the key array based on the length of the string-based key
        new->data = data;              //stores the user's data into the node
        strcpy(new->key,key);          //copies the key into the node
    
                                       //calling the hash function in the user's program
        index = table->hash_func;      //index will hold the hash table value for where the new 
        table->buckets[index] = new;   //Assigns the pointer at the index value to the new node
        table->total++;                //increment the total (total # of buckets)
    }
    

    HEADER FILE的部分:

    typedef struct hash_table_ {
        hash_entry **buckets;           //Pointer to a pointer to a Linked List of type hash_entry
        int (*hash_func)(char *);
        int (*cmp_func)(void *, void *);
        int size;
        void **sorted_array;      //Array used to sort each hash entry
        int index;//=0
        int total; //=0
        int sort_num; //=0  
    } hash_table, *Phash_table;
    

1 个答案:

答案 0 :(得分:0)

查看类型定义,您可以看到Phash_table是指向结构的指针,该结构的字段hash_func是一个函数,它接受char *并返回int

很可能你想要:

 index = table->hash_func(key);

因为它正在尝试将“指向函数的指针”分配给“int”,这非常无法满足您的需求。