title: How to get rid of segmentation error I am getting from my given code?
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;stdlib.h&gt;
  
  static int count = 0;
  struct node {
      int coef;
      int pow;
      struct node *link;
  };
  struct node *head = NULL;
  
  void showoff() { 
      struct node *t1;
      t1 = head;
  
      while (t1 != NULL) {
          printf("|%d|%d|%x|--", t1-&gt;coef, t1-&gt;pow, t1-&gt;link);
          t1 = t1-&gt;link;
      }
  }
  
  int main() {
      int n, i;
      struct node *temp, *t;
      t = head;
      printf("Number of nodes\n");
      scanf("%d", &amp;n);
  
      for (i = 0; i &lt; n; i++) {
          temp = (struct node*)malloc(sizeof(struct node));
          temp-&gt;coef = NULL;
          temp-&gt;pow = NULL;
  
          if (count == 0) {
              temp-&gt;link = head;
              head = temp;
          }
          if (count == 1) {
              temp-&gt;link = head-&gt;link;
              head-&gt;link = temp;
          }
          if (count &gt; 1) {
              while (t-&gt;link != NULL) {
                  t = t-&gt;link;
              }
              temp-&gt;link = t-&gt;link;
              t-&gt;link = temp;
          }
          count++;
      }
      showoff();
  }
  </code></pre>
  
  <p>When I tried to debug this program it shows Program received signal <code>*SIGSEGV*,Segmentation fault</code>. I don't know what to do that's why I posted this question. Problem is with <code>while(t-&gt;link != NULL)</code>, Logically the code is right, so what's should I do to run this program properly? Like what changes should I do, please help me cause this made me mad whole day.  </p>