I have been told to sort an array of structure(student) depending on one of its members(per) using bubble sort. I need to sort the 'student' structure in descending order of 'per'. Please help. I'm stuck!!

#include<stdio.h>
#include<conio.h>

struct student
{
       
       char sname[20],dept[25];
       int rollno;
       float per;
       
}s[30];

void accept(int );
void bubble(int[],int);
void print();

int main()
{
    
       int n;
       printf("\nHow Many Students Info ??");
       scanf("%d",&n);
       printf("\n");
       accept(n); 
       print(n);
       bubble(s[],n);      
       getch();
       return (0);        

}

void print(int no)
{
     int i;
     for(i=0;i<no;i++)
     {
                      printf("\n%d. Name :: %s\n   Department :: %s\n   Roll No. :: %d\n   Percentage :: %f\n\n",i+1,s[i].sname,s[i].dept,s[i].rollno,s[i].per);
     }
}

void accept(int no)
{
     
     int i;
     for(i=0;i<no;i++)
     {
             printf("\n\nEnter Details Of Student%d :: \n",i+1);
             printf("Enter Name :-  ");
             scanf("%s",s[i].sname);
             printf("\nEnter Department :-  ");
             scanf("%s",s[i].dept);
             printf("\nEnter Roll No. :-  ");
             scanf("%d",&s[i].rollno);
             printf("\nEnter Percentage :-  ");
             scanf("%f",&s[i].per);         
     }
     
}

void bubble(int a[],int n)  
{  
     int i,j,t;  
     for(i=n-2;i>=0;i--)  
     {  
        for(j=0;j<=i;j++)  
        {  
           if(a[j].per<a[j+1].per)  
           {  
              t=a[j];  
              a[j]=a[j+1];  
              a[j+1]=t;  
           }  
        }  
     }
}

I got the answer.. Following changes were made::

typedef struct
{
       
       char sname[20],dept[25];
       int rollno;
       float per;
       
}student;
 student s[30];

AND

void bubble(student a[],int n)  
{  
     int i,j;
     student t;  
     for(i=n-2;i>=0;i--)  
     {  
        for(j=0;j<=i;j++)  
        {  
           if(a[j].per<a[j+1].per)  
           {  
              t=a[j];  
              a[j]=a[j+1];  
              a[j+1]=t;  
           }  
        }  
     }
     print(n);
}
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.