title: Swapping structures in C
body: <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;ctype.h&gt;
  #include&lt;string.h&gt;
  
  struct name * create_node(char *,char *,int );
  struct name *add_node(struct name *,char *,char *,int);
  void output(struct name *,char *);
  void free_variables(struct name *);
  struct name *bubble_sort(struct name *,int);
  void swap(struct name **,struct name **);
  
  typedef struct name
  {
      char firstname[100];
      char secondname[100];
      int pno;
      struct name *next;
  }harsha;
  
  harsha *create_node(char *first,char *second, int phone)
  {
      harsha *pnode=(struct name *)malloc(sizeof(struct name));
      strcpy(pnode-&gt;firstname,first);
      strcpy(pnode-&gt;secondname,second);
      pnode-&gt;pno=phone;
      pnode-&gt;next=NULL;
      return pnode;
  }
  
  harsha *bubble_sort(harsha *pnode,int count)
  {
      int i,j,n;
  
      n=count;
      for(i=n;i&gt;1;i--)
      {
          for(j=1;j&lt;n;j++)
          {
              if(strcmp(pnode[j].firstname,pnode[j-1].firstname)&lt;0)
              {
                  swap(&amp;(pnode+j),&amp;(pnode+j-1));
              }
          }
      }
      return pnode;
  }
  
  void swap(harsha **pnode1,harsha **pnode2)
  {
      harsha *temp;
      temp=*pnode1;
      *pnode1=*pnode2;
      *pnode2=temp;
  }
  
  
  harsha *add_node(harsha *pnode,char *first,char *second,int phone)
  {
      if(pnode==NULL)
      {
          pnode=create_node(first,second,phone);
          return pnode;
      }
      else
      {
          while(pnode-&gt;next!=NULL)
          {
              pnode=pnode-&gt;next;
          }
          pnode-&gt;next=create_node(first,second,phone);
      }
      return pnode;
  }
  
  void output(harsha *pnode,char *str)
  {
      while(pnode-&gt;next!=NULL)
      {
          if(strcmp(pnode-&gt;secondname,str)==0)
          {
              printf("%s",pnode-&gt;firstname);
              printf("%d\n",pnode-&gt;pno);
          }
          pnode=pnode-&gt;next;
      }
      if(strcmp(pnode-&gt;secondname,str)==0)
          {
              printf("%s",pnode-&gt;firstname);
              printf("%d\n",pnode-&gt;pno);
          }
  }
  
  void free_variables(harsha *pnode)
  {
      if(pnode-&gt;next!=NULL)
      free_variables(pnode-&gt;next);
  
      free(pnode);
  }   
  
  int main()
  {
      harsha *head=NULL;
  
      //int i;
      char first[50];
      char second[50];
      char sname[50];
      int phone;
      char option='y';
      int count=0;
  
      while(tolower(option)=='y')
      {
          count++;
          printf("enter the first name:");
          scanf("%s",first);
  
          printf("enter the second name:");
          scanf("%s",second);
  
          printf("enter the phone number:");
          scanf("%d",&amp;phone);
          fflush(stdin);
          if (head==NULL)
          head=create_node(first,second,phone);
          else 
          add_node(head,first,second,phone);
  
          printf("enter the option:");
          scanf("%c",&amp;option);
  
      }
      fflush(stdin);
      head=bubble_sort(head,count);
      printf("enter the second name:");
      scanf("%s",sname);
  
      output(head,sname);
  
      free_variables(head);
  return 0;
  }
  </code></pre>
  
  <p>What I have done here is-I have created a linked list with the structures of personal information of an individual.After that I thought of sorting(ascending order) the linked list based on the first name of the structures.</p>
  
  <p>When I tried to run this program.I have got an error</p>
  
  <p>error:non-lvalue in unary `&amp;'</p>
  
  <p>while passing the parameters to the swap function in the bubble sort function.</p>
  
  <p>Can someone help me out and please explain what lvalue means.Thanks..</p>