C-指向结构的指针指向指针数组

C-指向结构的指针指向指针数组,c,C,我有一个链表,每个节点都有一个哈希表。哈希表由指向结构的指针数组实现。整个管理是通过指向链表的全局静态指针来完成的 我把问题改了一点!现在,问题更加集中。 在lookup and insert函数中,使我指定的代码更短 temp = cur_table->symbols_table[entry]; 但是我看到temp总是为空。 我不明白为什么会这样 代码分为以下三个模块。 提前谢谢你 symbols.h文件: #include <stdlib.h> #include <

我有一个链表,每个节点都有一个哈希表。哈希表由指向结构的指针数组实现。整个管理是通过指向链表的全局静态指针来完成的

我把问题改了一点!现在,问题更加集中。 在lookup and insert函数中,使我指定的代码更短

temp = cur_table->symbols_table[entry];
但是我看到temp总是为空。 我不明白为什么会这样

代码分为以下三个模块。 提前谢谢你

symbols.h文件:

#include <stdlib.h>
#include <stdio.h>

#define TABLE_SIZE 26

typedef struct symbol_node
{
  char* name;
  int type;
  int role;

  struct symbol_node* next;

} symbol_node;

typedef struct table_node
{
  struct symbol_node* symbols_table[TABLE_SIZE];
  struct table_node* prev;
  struct table_node* next;

} table_node;


static struct table_node* cur_table;

//functions declarations:
void init_table();
int hash_function(char* id);
symbol_node* lookup(char* id_name);
symbol_node* insert(char* id_name);
// debug
void printtable();

静态避免内存分配[`malloc']。试试看

cur_table = new table_node;

对于静态分配的内存,由于内存原因,无法设置值。插入时,它不是重新分配cur_表

运行时错误消息是什么?在调试器中运行代码时,您学到了什么?运行时错误是访问冲突,我看到主指针cur_表看起来没有初始化,尽管我创建了一个init函数。这段代码对我来说很好,如果我在返回主函数之前添加free语句,valgrind不会检测到任何泄漏。您能给我们看看hash_函数源代码吗?int hash_functionchar*id//返回数组中的索引{char c=*id;int index=intc;ifindex>=65&&index=97&&index解决了这个问题,因为'cur\u table'指针是在其他h文件中定义的。但是插入函数中还有另一个问题。当我分配'temp=cur\u table->symbols\u table[index];'时,临时值保持为空。
void main()
{
int i=0;
symbol_node* t = NULL;
symbol_node* tt = NULL;
init_table();

t = insert("markhit");
t = insert("mark");

tt = lookup("mark");

printtable();

_getch();

  free(t);
  free(tt);
  free(cur_table);
}
cur_table = new table_node;