title: How do I Print a Hash Table in C?
body: <p>I have a program in C that creates a hash table. I want to know what it is, but I am unsure how to print it out or display it.  I have pasted the program below. I am rather new to hash tables so any help would be greatly appreciated!</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  
  #define TABLE_SIZE  7
  #define NUM_INPUTS  7
  
  int hash( char *s )
          /* Note, this is a horrible hash function.  It's here for
                  instructional purposes */
  {
          return strlen( s ) % TABLE_SIZE ;
  }
  
  typedef struct entry
  {
          char *key;
          int     val;
          struct entry *next;
  } entry;
  
  entry* table[ TABLE_SIZE ] = { NULL };
  
  void insert( char *s, int v )
          /* this insert is NOT checking for duplicates.  :/ */
  {
          int h = hash( s );
          entry *t = (entry*) malloc( sizeof( entry ));
  
          t-&gt;key = s;
          t-&gt;val = v;
          t-&gt;next = table[h];
          table[h] = t;
  }
  
  void clean_table()
  {
          entry *p, *q;
          int i;
  
          for( i=0; i&lt;TABLE_SIZE; ++i )
          {
                  for( p=table[i]; p!=NULL; p=q )
                  {
                          q = p-&gt;next;
                          free( p );
                  }
          }       // for each entry
  }       // clean_table
  
  int main()
  {
          char* keyList[] = { "Jaga", "Jesse", "Cos", "Kate", "Nash", "Vera",
                  "Bob" };
  
          int valList[] = { 24, 78, 86, 28, 11, 99, 38 };
  
          int i;
  
          for( i=0; i&lt;NUM_INPUTS; ++i )
                  insert( keyList[i], valList[i] );
  
          /* what does the table look like here? */
  
          clean_table();
  
          return( 0 );
  }   
  </code></pre>