【发布时间】:2012-05-06 18:22:31
【问题描述】:
请看我的最后一行。我将如何打印这个?我该如何施放它?我要投它(word*)table_p -> buckets_array[0] -> data -> key 和(word*)table_p -> buckets_array[0] -> data -> frequency 吗?
typedef struct data_{
char *key;
void *data;
struct data_ *next;
}data_el;
typedef struct hash_table_ {
/* structure definition goes here */
data_el **buckets_array;
} hash_table, *Phash_table;
typedef struct word_{
char key[WORD_SIZE];
int frequency;
} word;
word *new_word;
new_word = (word *)malloc(sizeof(word));
new_word->frequency = 5;
new_word->key = "Lalalal";
Phash_table table_p;
table_p = (Phash_table)malloc(sizeof(hash_table));
table_p->buckets_array = (data_el **)malloc(sizeof(data_el *)*(size+1));
table_p->buckets_array[0]->data = (void*)new_word;
/*Is this right? How do I cast this? (word*) ?*/
printf("Key :%s Frequency:%d ",table_p->buckets_array[0]->data->key,
table_p->buckets_array[0]->data->frequency);
【问题讨论】:
标签: c pointers casting structure