我正在尝试将 char 数组设置到结构中,但是当我尝试将其打印出来时。我得到一个分段错误。我究竟做错了什么?
typedef struct buckets_{
char *key;
data *next;
}buckets;
typedef struct hash_table_ {
int (*hash_func)(char *);
int (*comp_func)(void*, void*);
buckets **buckets_array;
} hash_table, *Phash_table;
table_p -> buckets_array[0] = malloc(sizeof(buckets));
table_p -> buckets_array[1] = malloc(sizeof(buckets));
char word2[5] = "Hieo";
table_p -> buckets_array[1] -> key = malloc(sizeof(word2));
table_p -> buckets_array[1] -> key = word2;
printf("%s",table_p -> buckets_array[i] -> key); /*Getting segmitation falut here*/
Opp 忘了提到我有一个分配数组的函数。假设我分配了数组。