小编Igo*_*r K的帖子

为什么这个malloc在C中不起作用?

只是尝试制作一种哈希表,每个节点都是一个链表.

刚刚初始化空间时遇到麻烦,我做错了什么?

#include <stdlib.h>

typedef struct entry {
 struct entry *next;
 void *theData;
} Entry;


typedef struct HashTable {
 Entry **table;
 int size;
} HashTable;

int main(){
 HashTable *ml;
 ml = initialize();
 return 0;
}

HashTable *initialize(void)
{
 HashTable *p;
 Entry **b;
 int i;


 if ((p = (HashTable *)malloc(sizeof(HashTable *))) == NULL)
  return NULL;
 p->size = 101;

 if ((b = (Entry **)malloc(p->size * sizeof(Entry **))) == NULL)
         return NULL;

 p->table = b;

 for(i = 0; i < p->size; i++) { …
Run Code Online (Sandbox Code Playgroud)

c malloc pointers

0
推荐指数
1
解决办法
905
查看次数

标签 统计

c ×1

malloc ×1

pointers ×1