2012-05-01 15 views
0

私はエラーを取得しておく:コマンドを使用して、私のハッシュテーブルのADTをコンパイルしようとしたときは、ハッシュテーブルADTをコンパイルすることはできません - C

  1. 割り当ては、キャスト

なしポインタから整数を作る:

gcc hash_NEW.c -c 

1つの関数で大きな.cファイルにエラーが発生しました。事前に助けを おかげ

エラー1行にここに起こる(インデックス=卓上> 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; 

答えて

0

Phash_tableは、フィールドhash_funcchar *を受け取り、intを返す関数である構造体へのポインタであることがわかります。

は、おそらくあなたがしたい:

index = table->hash_func(key); 

それはあなたが必要なものであることを非常にunlikeyある「INT」に「関数へのポインタ」を割り当てるしようとしている立っているよう。

+0

ええ私はそれを投稿した直後に2番目のものを見つけました。私はその構造体に関連するヘッダファイルの部分を追加しました。あなたが提供したコードは確かに訂正です。そのようにして、私はkeyの引数でユーザーのハッシュ関数を呼び出します。したがって、正しいインデックス値を取得し直してください。ああ、意味がある!早速のご返事ありがとうございます!! –

+0

今、それはコンパイルされます!素晴らしい、私は十分にあなたに感謝しない、私はこれを見て新鮮な目が必要 –

+0

yw。 'strcpy(new-> key、key);行を見てください。あなたは苦労するつもりです。 –

関連する問題