我不确定我需要使用什么作为参数来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;
};