title: Segmentation Fault in Hashtable
body: <p>I was trying to implement a hash table that stores the word of English language. So to be in brief, I used an array of linked list ( <strong>Chaining</strong> ) , I haven't made the entire program but just implemented so that It takes a single word input and searches it through the hash table but it starts giving me Segmentation fault. Please help me on this one....
  Thank you in advance !</p>
  
  <pre><code>strcpy(new-&gt;s,val);
  </code></pre>
  
  <p>This is the line where I got stuck with the Segmentation Fault.</p>
  
  <p>My entire code :</p>
  
  <pre><code>#include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct node
  {
  string s;
  struct node *next;
  }node;
  
  node* create(char*);
  
  unsigned long sdbm(unsigned char*);
  
  bool search(string s,node *first)
  {
  node *ptr=first;
  bool found=false;
  
  while(ptr-&gt;next!=NULL)
  {
      if(strcmp(ptr-&gt;s,s)==0)
      {
          found=true;
          break;
      }
  
  }
  
  if(found==true)
  return true;
  else
  return false;
  }
  
  
  
  int main(void)
  {
  node a[26];
  printf("Enter the string\n");
  string s=get_string();
  unsigned long hashcode = sdbm((unsigned char*)s);
  printf("The hashcode is %lu\n", hashcode);
  
  a[hashcode].next=create(s);
  
  printf("Enter the string to be searched among the ones you recently typed 
  in\n");
  string t=get_string();
  
  if(search(t,&amp;a[sdbm((unsigned char*)t)]) == true)
  printf("found\n");
  else
  printf("not found\n");
  
  }
  
  
  node* create(string val)
  {
  node* new = malloc(sizeof(node));
  if(new!=NULL)
  {
      new-&gt;s="";
  
      strcpy(new-&gt;s,val);   // this is the part ehere I get Segmentation Fault
      new-&gt;next=NULL;
  }
  
  return new;
  
  }
  
  unsigned long
  sdbm(unsigned char *str)
  {
      unsigned long hash = 0;
      int c;
  
      while ((c = *str++)!=0)
          hash = c + (hash &lt;&lt; 6) + (hash &lt;&lt; 16) - hash;
  
      return hash%26;
  }
  </code></pre>