【问题标题】:How do I get an array of pointers to a structures? [closed]如何获取指向结构的指针数组? [关闭]
【发布时间】:2012-04-29 22:09:53
【问题描述】:

我需要创建一个头指针数组。

typedef struct data_{
  void *data;
  struct data_ *next;
}data;

typedef struct buckets_{
  data *data;
  void *key;
}buckets;

typedef struct hash_table_ {
  buckets **buckets_array;
} hash_table, *Phash_table;

Phash_table table_p;
table_p = (void *)malloc(sizeof(hash_table));
table_p -> buckets_array = (void **)malloc(sizeof(buckets buckets)*size); 
/*Line #7*/

当我尝试编译时,我得到了这个

hash.c:7:62: error: expected ')' before 'buckets'
hash.c:7:28: warning: assignment from incompatible pointer type [enabled by default]

我正在尝试获取一组存储桶,每个存储桶将指向一个链表。 我在正确的道路上吗?

【问题讨论】:

  • sizeof(buckets buckets) - 你已经写了两次buckets

标签: c arrays pointers structure


【解决方案1】:

你有一个错字。我想你想写

table_p -> buckets_array = (void **)malloc(sizeof(buckets)*size); 

【讨论】:

  • Nvm (void **) 导致了问题。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2017-09-01
  • 2011-02-01
  • 1970-01-01
  • 2017-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多