title: Split a single linked list into 2 SIngly linked lists -one containing nodes with even data and other containing nodes with odd data
body: <p>I tried coding the above problem but I'm getting a segmentation error.Below is the code that I've written :</p>
  
  <pre><code>       #include&lt;stdio.h&gt;
         #include&lt;stdlib.h&gt;
         #include&lt;math.h&gt;
         struct oddeven
         {
             int data;
             struct oddeven *link;
         };
         typedef struct oddeven m;
         int main()
         {
              int z;
              m *head=NULL,*ptr,*current;
              m *x,*y,*q,*head1=NULL,*current1,*head2=NULL,*current2; 
              while(1)
              {
                   int ch;
                   ptr=(m*)malloc(sizeof(m));
                   printf("Enter the data: ");
                   scanf("%d",&amp;ptr-&gt;data);
                   ptr-&gt;link=NULL;
                   if(head==NULL)
                   {
                       head=ptr;
                       current=ptr;
                   }
                   else 
                   {
                       current-&gt;link=ptr;
                       current=ptr;
                   }
                   printf("Do you want to continue?Y=1/N=0");
                   scanf("%d",&amp;ch);
                   if(ch!=1)
                       break;
               }
               x=head;
               while(x!=NULL)
               {
                    z=x-&gt;data;
                    if(z%2==0)
                    {
                         ptr=(m*)malloc(sizeof(m));
                         ptr-&gt;data=z;
                         ptr-&gt;link=NULL;
                         if(head1==NULL)
                         {
                              head1=ptr;
                              current1=ptr;
                         }
                         else
                         {
                              current1-&gt;link=ptr;
                              current1=ptr;
                         }
  
                    }
                   else
                   {
                         ptr=(m*)malloc(sizeof(m));
                         ptr-&gt;data=z;
                         ptr-&gt;link=NULL;
                         if(head2=NULL)
                         {
                              head2=ptr;
                              current2=ptr;
                         }
                         else
                         {
                             current2-&gt;link=ptr;
                             current2=ptr;
                         }
                    }
                    x=x-&gt;link;    
              }
              y=head1;
              q=head2;
              while (y!=NULL)
              {
                  printf("%d\t",y-&gt;data); 
                  y=y-&gt;link;
              }
              printf("\n");
              while (q!=NULL)
              {
                    printf("%d\t",q-&gt;data);
                    q=q-&gt;link;
              } 
        }
  </code></pre>
  
  <p>I can't figure out where am I going wrong. Any help would be much appreciated.
  It takes the inputs but after that it says segmentation error. Split the given single linked list into two where I can store the odd vales and even values separately .I tried different methods but couldn't get it to work.</p>