title: linked lists : student database >> help needed
body: <p>in need help to write the right code plz 
  q:Write a program which organizes a simple database of student information.</p>
  
  <p>The program should allow the user to enter a sequence of student data records. Each student data record has three fields: first name, last name, and age. The user should be able to perform the following 4 operations: 1) enter a record, 2) delete a record, 3) print all records, and 4) sort all records. All 4 options should be printed at the beginning. The user should receive a prompt where he/she can enter the number coresponding to the operation he wants to perform. The enter a record operation will prompt the user to type in three strings on the same line, one string per field. The print all records operation should print each record on a different line. The sort all records operation should sort based on last name.</p>
  
  <p>the code i wrote is: (disply and add are working, but delete and sorting are not!)</p>
  
  <pre><code>        #include&lt;stdio.h&gt;
      #include&lt;stdlib.h&gt;
      #include&lt;malloc.h&gt;
  
  
       struct student
        {
           char fname[29];
           char lname[29];
           int age;
           struct student *next;
        };
  
        int main()
        {
          int i,n,ch,ps,x,k;
          k=0;
        struct student *h,*t,*t1,*w,*q;
        h=NULL;
  
        printf("\n/* student data records*/");
  
  
      while(1)
       {
            printf("\n1.display\n2:add\n3.delete\n4.exit\n5.sort by first name\n");
              printf("\nenter your choice=");
            scanf("%d",&amp;ch);
            switch(ch)
      {
      case 1:
        if(h==NULL)
         {
          printf("no records are available");
        }
        w=h;
        while(w!=NULL)
       {
          printf("\nfirst name of a student:%s\nlast name of a student:%s\nage of a student:%d\n",
        w-&gt;fname,w-&gt;lname,w-&gt;age);
        w=w-&gt;next;
       }
      break;
  
      case 2:
         printf("\nenter the new record=\t");
         if(h==NULL)
       {
        h=t=(struct student *)malloc(sizeof(struct student));
         printf("\nfirst Name of a student:\t");
          scanf("%s",&amp;t-&gt;fname);
          printf("\nlast Name of a student:\t");
          scanf("%s",&amp;t-&gt;lname);
          printf("\nage of a student:\t");
          scanf("%d",&amp;t-&gt;age);
         t-&gt;next=NULL;
      break;
      }
      else
        {
          t1=(struct student *)malloc(sizeof(struct student));
          printf("\nFirst Name of a student:\t");
          scanf("%s",&amp;t1-&gt;fname);
          printf("\nlast Name of a student:\t");
          scanf("%s",&amp;t1-&gt;lname);
          printf("\nage of a student:\t");
          scanf("%d",&amp;t1-&gt;age);
          t1-&gt;next=t-&gt;next;
          t-&gt;next=t1;
          t=t1;
      }
      break;
  
      case 3:
          printf("enter name of student whos record is to be deleted=\n");
          scanf("%d",&amp;ps);
          t=h;
       while(t-&gt;fname!=ps-1)
         {
           t=t-&gt;next;
          }
           t1=t-&gt;next;
           t-&gt;next=t1-&gt;next;
           free(t1);
       break;
  
      case 4:
       exit(0);
       break;
  
      case 5:
      printf("not working yet");
      {
      void sort( student[],int n)
       { int i,j,comp=0,passes=0;
         student temp;
         for(i=1;i&lt;n;i++)
          {
             passes++;
             for(j=0;j&lt;n-i;j++)
          {      comp++;
                 if(st[j].lname &lt; st[j+1].lname)
                 {  temp=st[j];
                    st[j]=st[j+1];
                    st[j+1]=temp;
                 }
          }
          }
       }
      }
      break;
      }
      }
      }
  </code></pre>