title: Remove errors from code of sparse matrix using linked list
body: <p>Not getting any error on running the code. On debugging Segmentation fault on <strong>if(j ==
  temp-&gt;col)</strong> when j = 4</p>
  <p>Create function &quot;seems&quot; to have created the function well but I'm unsure why the segmentation fault.</p>
  <p>The matrix(5x6) I input was
  0 0 0 0 0 1\n
  1 0 0 0 0 1\n
  1 1 0 0 0 1\n
  1 1 1 1 0 0\n
  0 0 0 0 1 1\n</p>
  <p>The output I received was
  0 0 0 0 0 1\n
  1 0 0 0 0 1\n
  1 1 0 0 0 1\n
  1 1 1 1</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct node{
    int col;
    int data;
    struct node *next;
  }*first;
  
  void create(struct node *A[], int m, int n){
    struct node *temp, *last;
    int noe, flag = 0;
    for(int i = 0; i &lt; m; i++){
      flag = 0;
      A[i] = (struct node *) malloc(sizeof(struct node));
      last = A[i];
      
      printf(&quot;Enter no. of items in Row %d :&quot;, i);
      scanf(&quot;%d&quot;, &amp;noe);
  
      for(int j = 0; j &lt; noe; j++){
        temp = (struct node *) malloc(sizeof(struct node));
        
        printf(&quot;Enter column and elmeent :&quot;);
        scanf(&quot;%d%d&quot;, &amp;temp-&gt;col, &amp;temp-&gt;data);
        
        temp-&gt;next = NULL;
        if(last == A[i] &amp;&amp; flag == 0){
          A[i] = temp;
          flag = 1;
        }
        else
          last-&gt;next = temp;
  
        last = temp;
  
      }
      last = NULL;
    }
  }
  
  void display(struct node *A[], int m, int n){
    struct node *temp;
    for(int i = 0; i &lt; m; i++){
      temp = A[i];
      for(int j = 0; j &lt; n; j++){
        if(j == temp-&gt;col){
          printf(&quot;%d &quot;, temp-&gt;data);
          temp = temp-&gt;next;
        }
        else
          printf(&quot;0 &quot;);
      }
      printf(&quot;\n&quot;);
    }
  }
  
  int main(){
    
    int m = 5, n = 6;
    struct node *A[m];
  
    create(A, m, n);
    display(A, m, n);
  
    return 0;
  }
  </code></pre>