Im having trouble sorting the name array in my bubble sort. The sort works fine with just the account number and balance, but when i add the name into it it doesnt work. Im sure it has something to do with the fact that name is an array, but i dont know how to fix this problem. Any help would be greatly appreciated.
Code:#include <stdio.h>
main()
{
/*Variables*/
/*-------------------------------------------------------------------------------*/
struct info{char name[30]; int account_num; float balance;
};
struct info people[25];
int x,a,y,temp=0;
/*------------------------------------------------------------------------------*/
/*Heading*/
/*-------------------------------------------------------------------------------*
//*Loop to collect info*/
for(x = 1; x <= 3; ++x)
{
printf("Enter Name: ");
scanf("%s",people[x].name);
printf("Enter Account Number: ");
scanf("%i",&people[x].account_num);
printf("Enter Balance: ");
scanf("%f",&people[x].balance);
printf("\n");
}
for (a=1; a<x-1;++a)
{
for (x=1; x<3;++x)
{
if (people[x+1].account_num>people[x].account_num)
{
temp = people[x].account_num;
people[x].account_num = people[x+1].account_num;
people[x+1].account_num = temp;
temp = people[x].name;
people[x].name = people[x+1].name;
people[x+1].name = temp;
temp = people[x].balance;
people[x].balance = people[x+1].balance;
people[x+1].balance = temp;
}/*end if*/
}/*end nested for*/
}/*end for loop*/
/*Loop to print Sorted grades*/
for (y=1; y<=3;++y)
{
printf("%i %s %.2f \n, ",people[y].account_num, people[y].name, people[y].balance);
} /*end for*/
printf("\n\n");
}