title: How to avoid segmentation fault with linked lists
body: <p>I would like to make a code that uses linked list, takes input from the terminal and then print a table out.</p>
  <p>In this example, I am uploading some information from element table.</p>
  <p>I get segmentation error.</p>
  <p>Somebody can help me to understand why?</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct element{
      char name[20];
      char symbol[20];
      float atom_weight;
      struct Element* next;
  } element;
  
  
  /* Add a new node to the top of a list */
  element* insert_top(char name[20], char symbol[20], float atom_weight, element* head) {
      element *new_element;
      new_element = (element *) malloc(sizeof(element));
      new_element-&gt;name[20] = name;
      new_element-&gt;symbol[20] = symbol;
      new_element-&gt;atom_weight = atom_weight;
  
      new_element-&gt;next= head;
      head = new_element;
      printf(&quot;Top inserted&quot;);
      return head;
  }
  
  element* table=NULL;
  int main()
  {
      int choice=1, i=0;
      char name[256];
      char symbol[256];
      float atom_weight;
  
      printf(&quot;%d&quot;, choice);
      while (choice!=0){
  
          printf(&quot;\n Please enter element name:&quot;);
          scanf(&quot;%s&quot;, name);
  
          printf(&quot;\n Please enter element symbol:&quot;);
          scanf(&quot;%s&quot;, symbol);
  
          printf(&quot;\n Please enter atomic weight:&quot;);
          scanf(&quot;%f&quot;, &amp;atom_weight);
  
  
          //printf(&quot;%s, %s,...Weight %f&quot;,name, symbol, atom_weight);
          insert_top(name, symbol, atom_weight, table);
  
          i=i+1;
          printf(&quot;\nDo you want to continue (Y=1/N=0)? &quot;);
          scanf(&quot;%d&quot;, &amp;choice); //You should add the space before %c, not after
  
      }
      printf(&quot;Out of cycle\n&quot;);
      printf(&quot;Size of table %lu\n&quot;, sizeof(table));
  
      printf(&quot;Weight %f&quot;,table-&gt;atom_weight);
  
  
      while (table-&gt;next != NULL){
          printf(&quot;\nElement: %s \t\t Symbol: %s  \t\t Atomic weight: %f\n&quot;,table[i].name, table[i].symbol,table[i].atom_&gt;
          //printf(&quot;ciao&quot;);
          table=table-&gt;next;
      }
  }
  
  </code></pre>