0

我不断收到错误:

  1. 赋值从没有强制转换的指针生成整数

尝试使用以下命令编译我的哈希表 ADT 时:

gcc hash_NEW.c -c

该错误是在较大的 .c 文件中的 1 个函数中遇到的。我在这里先向您的帮助表示感谢

错误 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)
}

部分头文件:

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;
4

1 回答 1

0

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

很可能你想要:

 index = table->hash_func(key);

就目前而言,您正在尝试将“指向函数的指针”分配给“int”,这不太可能成为您所需要的。

于 2012-05-01T22:47:44.597 回答