我不断收到错误:
- 赋值从没有强制转换的指针生成整数
尝试使用以下命令编译我的哈希表 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;