title: Returning a dynamically allocated array of structures from a function in C?
body: <pre><code>typedef struct {
      List *table;
      unsigned int size;
  } HashTable;
  
  typedef struct node {
      Data data;
      struct node *next;
  } NODE;
  
  struct listptrs {
      NODE *tail;
      NODE *head;
      NODE *prev;
      NODE *current;
  };
  
  typedef struct listptrs List;
  
  HashTable createHashTable(unsigned int size) {
      //HashTable htable = { 0 };
      //return htable;
  
      int i;
      HashTable *htable = NULL;
      htable = malloc(sizeof(HashTable) * size);
  
      for (i = 0; i &lt; size; i++) {
          htable[i].table = malloc(sizeof(List));
          htable[i].table-&gt;current = NULL;
          htable[i].table-&gt;head = NULL;
          htable[i].table-&gt;prev = NULL;
          htable[i].table-&gt;tail = NULL;
          htable[i].size = size;
      }
      return *htable;//???
  }
  </code></pre>
  
  <p>Then in main:</p>
  
  <pre><code>HashTable htable = createHashTable(tableSize);
  </code></pre>
  
  <p><code>htable</code> doesn't act like an array at all. Any ideas how to solve it without changing any return value from the function and arguments for functions? This is part of a school assignment and only the contents of the function <code>createHashTable</code> may be changed. The rest of the program is not here because it isn't relevant to the question.</p>