title: Why does my code skip over certain nodes?
body: <p>I'm writing this code to store data records of students' first name, last name, scores and zip codes. I have almost everything done but my Print() function doesn't print the first element of node 2(first name of 2nd student) and turns into an infinite loop when I input ore than 2 nodes, what am i doing wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include&lt;stdlib.h&gt;
  void Insert(char first[20], char last[20], float data, char zip[50]);
  void delete(int e);
  void Print();
  double median();
  struct node
  {
      char first_name[20];
      char last_name[20];
      float score;
      char zip_code[50];
      struct node *ptr;
  };
  int n;
  struct node* head =NULL;
  struct node* tail=NULL ;
  void Insert(char first[20], char last[20], float data, char zip[50])
  {
  
      struct node *temp=(struct node*)malloc(sizeof(struct node));
  temp-&gt;ptr=NULL;
      strcpy(temp-&gt;first_name,first);
      strcpy(temp-&gt;last_name,last);
      temp-&gt;score=data;
      strcpy(temp-&gt;zip_code,zip);
  
      if(head==NULL)
      {
          head=temp;
          tail=temp;
          return;
      }
      tail-&gt;ptr=temp;
      tail=temp;
      free(temp);
      temp=NULL;
  
  }
  void delete(int e)
  {
      int i;
      struct node *temp=(struct node*)malloc(sizeof(struct node));
      temp=head;
      if(e==1)
      {
          head=temp-&gt;ptr;
          free(temp);
          return;
      }
      else if(e==n)
      {
          while(temp-&gt;ptr-&gt;ptr!=NULL)
          {
              temp=temp-&gt;ptr;
          }
          temp-&gt;ptr=NULL;
          free(temp-&gt;ptr);
          return;
      }
      for(i=0; i&lt;(e-2); ++i)
          temp=temp-&gt;ptr;
      struct node *temp1=temp-&gt;ptr;
      temp-&gt;ptr=temp1-&gt;ptr;
      free(temp1);
  }
  void Print()
  {
      struct node *temp=(struct node*)malloc(sizeof(struct node));
      temp=head;
      printf("Data entered is below: \n");
      while(temp!=NULL)
      {
  
          printf("First Name: %s, Last Name: %s, Score: %.2f, Zip Code: %s",temp-&gt;first_name,temp-&gt;last_name,temp-&gt;score,temp-&gt;zip_code);
          temp=temp-&gt;ptr;
          printf("\n");
      }
      printf("\n\n\n");
  }
  double median()
  {
      double median,tmp;;
      double *ex=(double*)malloc(sizeof(double));/*head*/
      double *exe=(double*)malloc(sizeof(double));/*dynamic*/
      ex=exe;
      int i=1,term,j;
      struct node *temp=(struct node*)malloc(sizeof(struct node));
      temp=head;
      while(i&lt;=n)
      {
          temp-&gt;ptr;
          *exe=temp-&gt;score;
  
          exe++;
      }
      for(i=0; i&lt;n; i++)
      {
          for(j=i+1; j&lt;n; j++)
          {
              if( *(ex+i) &gt; *(ex+j))
              {
                  tmp = *(ex+i);
                  *(ex+i) = *(ex+j);
                  *(ex+j) = tmp;
              }
          }
      }
      if(n%2==0)
      {
          /*even;median=n/2-1*/
  
          term=(n/2)-1;
          median= (*(ex+(term-1)));
          return median;
      }
      /*odd; median=n-1/2*/
      term=(n-1)/2;
      median= (*(ex+(term-1)));
  
      return median;
  }
  int main()
  {
      char name1[20],name2[20], code[50];
      float x;
      int i,option,index;
      printf("Enter the number of nodes: ");
      scanf("%d",&amp;n);
      printf("Please enter the records of students in the following format(click enter for new students)\n");
      printf("First_Name Last_Name Score Zip_Code\n");
      for(i=1; i&lt;=n; ++i)
      {
  
          scanf(" %s",name1);
          scanf(" %s",name2);
          scanf(" %f",&amp;x);
          scanf(" %s",code);
          Insert(name1,name2,x,code);
  
      }
      printf("\n");
      while(1)
      {
          printf("Choose one of the following options: \n");
          printf("Print records (press 1)\nAdd a new record (press 2)\nDelete record(s) (press 3)\nSearch by zip code (press 4)\nSearch by score range (press 5)\nFind median score (press 6)\nExit the program (press 0)\n");
          scanf("%d",&amp;option);
          switch(option)
          {
          case 0:
          {
              /*Exit Program*/
              exit(0);
              break;
          }
          case 1:
          {
              /*print*/
              Print();
              break;
          }
          case 2:
          {
              /*insert*/
              getchar();
              printf("Enter the new record in the following format: \nFirst_Name Last_Name Score Zip_Code\n");
              scanf("%s",name1);
              scanf("%s",name2);
              scanf("%f",&amp;x);
              scanf("%s",code);
              getchar();
              Insert(name1,name2,x,code);
  
              break;
          }
          case 3:
          {
              /*delete*/
              printf("Enter the node/record to be deleted: ");
              scanf("%d",&amp;index);
              delete(index);
              printf("The deletion of record %d has been succesfully completed!\n\n",index);
              break;
          }
          case 4:
          {
              /*search by zip*/
  
              break;
          }
          case 5:
          {
              /*search by score*/
  
              break;
          }
          case 6:
          {
              /*find median*/
              printf("Median score for the entered records is: %f",median());
              break;
          }
  
          }/*switch*/
      }/*while*/
      return 0;
  
  }
  </code></pre>