一个指针数组的排序问题
我写了一个对名字进行排序的程序,有三个模块:主函数,排序函数,输出函数:***************主函数*****************
#include<stdio.h>
#include<string.h>
int main()
{
void sort1(char *name[],int n);//冒泡排序
void prin(char *name[],int n);
char *name[]={
"shenshitin","zhengjialiang","zhangmin",
"puhuarong","moqingqing","zhengyongfa",
"liuziling","chenjun","qianrong","chenminghui",
"xuxiuju","zhongbin","laixingyin",
"meireguili","bahetiluer","kudireti","wuxiaoli"};
int n=17;
printf("*****冒泡排序*****\n");
sort1(name,n);
prin(name,n);
return 0;
}
***************排序函数**************(冒泡排序)
void sort1(char *name[],int n)
{
char *remp;
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(strcmp(name[j],name[j+1])>0)
{
remp=name[j];
name[j]=name[j+1];
name[j+1]=name[j];
}
}
}
}
**************输出函数****************
void prin(char *name[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%d:%s\n",i+1,name[i]);
}
}
语法上没有错误,但是调试的结果是这样的:只储存了最后三个字符串。