无法实现名字的排序.
//无法实现书名的排序,求!指点.#include<stdio.h>
#include<string.h>
struct book
{
char name[10];
float price;
}
pers[10];
void change(void);
void print_book(void);
void putinbook(void);
void main()
{
putinbook();
print_book();
change();
printf("That's ok!\n");
system("pause");
}
void print_book(void)
{
int i;
printf("the first turn:\n");
for(i=0;i<10;i++)
printf("%s\t%g\n",pers[i].name,pers[i].price);
}
void putinbook(void)
{
int i;
printf("Please input 10 books name,price:\n");
for(i=0;i<10;i++)
scanf("%s %f",pers[i].name,&pers[i].price);
}
void change(void)
{
int i,finish,j;
float min;
char minname[10];
printf("the turn after sort:\n");
printf("book name\tbook price\n");
for(i=0;i<10;i++)
{
finish=1;
for(j=0;j<10;j++)
{
if(pers[j].price<pers[j+1].price)
{
min=pers[j].price;
pers[j].price=pers[j+1].price;
pers[j+1].price=min;
strcpy(minname,pers[j].name);
strcpy(pers[j].name,pers[j+1].name);
strcpy(pers[j+1].name,minname);
finish=0;
}
if(name[j]>name[j+1])
{
min=name[j];
name[j]=name[j+1];
name[j+1]=min;
strcpy(name[j],name[j+1]);
strcpy(name[j+1],minname);
finish=0;
}
}
if(finish==1)
break;
}
for(i=0;i<10;i++)
printf("%s\t\t%g\n",pers[i].name,pers[i].price);
}