title: C - pointer to struct to array of pointers
body: <p>I have a linked list with a hash table in each node. The hash table is implemented by an array of pointers to structs. The whole management of this is made by a global static pointer to the linked list.</p>
  
  <ul>
  <li>I changed a little bit the question! Now the question is more focused.</li>
  </ul>
  
  <p>in the lookup and insert function to make the code shorter I assign </p>
  
  <pre><code>temp = cur_table-&gt;symbols_table[entry];
  </code></pre>
  
  <p>but I see that temp gets NULL all the time.
  I can't understand why is that happens?</p>
  
  <p>The code is below in 3 modules.
  Thank you in ahead.</p>
  
  <p>symbols.h file:    </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  #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();
  </code></pre>
  
  <p>symbols.c</p>
  
  <pre><code> void init_table() // creates the first node                                                                                                                                                                        
   {
    int i = 0;
    cur_table = NULL;
  
    cur_table = (table_node*)malloc(sizeof(table_node));
  
    cur_table-&gt;prev = NULL;
    cur_table-&gt;next = NULL;
  
    for(i=0; i &lt; TABLE_SIZE; i++)
      {
        cur_table-&gt;symbols_table[i] = NULL;
      }
  }
  
  symbol_node* lookup(char* id_name)  // returns null if the id name not found                                                                                                                                       
  {
    symbol_node* result = NULL;
    symbol_node* temp = NULL;
    int entry = atoi(id_name);
  
    temp = cur_table-&gt;symbols_table[entry];
  
    while(temp != NULL)
      {
        if( strcmp( id_name, temp-&gt;name ) == 0 )
      {
            result = temp;
            break;
          }
        else
          temp = temp-&gt;next;
      }
  
    return result;
  }
  
  
  symbol_node* insert(char* id_name)
  {
    symbol_node* result = NULL;
    symbol_node* temp = NULL;
    int index = -1;
  
    if(lookup(id_name)==NULL)
      {
        index = atoi(id_name);
        temp = cur_table-&gt;symbols_table[index];
  
        while(temp!=NULL)
          {
            temp = temp-&gt;next;
          }
  
        temp = (symbol_node*)malloc(sizeof(symbol_node));
        temp-&gt;next = NULL;
        temp-&gt;name = id_name;
        // TODO: other params                                                                                                                                                                                        
  
        result = temp;
      }
  
    return result;
  }
  void printtable()
  {
  int i=0;
  
  for(i=0; i&lt;TABLE_SIZE; i++)
  {
      if(cur_table-&gt;symbols_table[i]==NULL)
          printf("NULL at index %d\n",i);
      else
          printf("There are something\n");
  }
  }
  </code></pre>
  
  <p>main.c</p>
  
  <pre><code>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);
  }
  </code></pre>