i'm trying to insert and element in a list in alphabetical order last name first and then first name here is my code but not working please help

struct node * Inserting(struct node *tp,struct node *fp)
 {
  struct node *last = NULL;
  struct node *old, *start;
  start = fp;

  if(!last)
  {
   tp->nextptr = NULL;
   last = tp;
   return tp;
   }
   old = NULL;
   while(fp)
   {
    if(strcmp(fp->lastname,tp->lastname) < 0)
    {
     old = fp;
     fp = fp->nextptr;
     }
     else
     {
      if (old)
      {
       old->nextptr = tp;
       tp->nextptr = fp;
       return start;
       }
       tp->nextptr = fp;
       return tp;
       }
    }
    last->nextptr = tp;
    tp->nextptr = NULL;
    last = tp;
    return start;

Code tags added. -Narue

>if(!last)
This will always be true.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.