我不确定我需要使用什么作为malloc的参数来在table_allocate(int)函数中分配空间.我只想到count_table*cTable = malloc(sizeof(count_table*)),但这对size参数没有任何作用.我应该为list_node_t分配空间吗?以下是我正在使用的内容.
在.h文件中我给了这个签名:
//create a count table struct and allocate space for it //return it as a pointer count_table_t* table_allocate(int);
以下是我应该使用的结构:
typedef struct list_node list_node_t;
struct list_node {
char *key;
int value;
//the next node in the list
list_node_t *next;
};
typedef struct count_table count_table_t;
struct count_table {
int size;
//an array of list_node pointers
list_node_t **list_array;
};
谢谢!