求教
函数void sort(struct T items[],int low,int high)的功能是:对items结构数组中从下标low开始到high为止的所有数组元素按成员name以字典序排序,并输出排序后的结果。含有错误的源程序如下:
#include <stdio.h>
#include <string.h>
struct T
{char name [20],num[20];
};
void sort(struct T items[],int low,int high)
{struct T temp;
int k,j;
for(k=low;k<high;k++)
for(j=k;j<high-k-1;j++)
if(items[j].name>items[j+1].name)
{temp=items[j];items[j]=items[j+1];items[j+1]=temp;}
}
void main(void)
{struct T stu[4]={{"Wang","6723"},{"Cai","2106"},{"Zhang",
"5129"},{"Chang","4512"},{"An","6868"}};
int k;
sort(stu,0,4);
printf("The Sorted Array:\n");
for(k=0;k<5;k++)
printf("name:%s,num:%s\n",stu[k]->name,stu[k]->num); }