#include <stdio.h>
#include <string.h>
int main()
{
void sort(char * pstr[5]);
int i;
char str[5][50]= {“asdfadsf”,“oiuyoiuy”,“lkwjerht”,“uytr”,“qoiurty”};
char * pstr[5];
printf(“排序前:\n”);
for(i=0; i<5; i++)
{
pstr[i]=str[i];
printf("%s\n",pstr[i]);
}
//对字符串排序
sort(pstr);
printf(“排序后:\n”);
for(i=0; i<5; i++)
{
printf("%s\n",pstr[i]);
}
return 0;
}
void sort(char * pstr[5])
{
char * t;
int i,j;
for(i=0; i<5; i++)
{
for(j=i+1; j<5; j++)
{
if(strcmp(pstr[i],pstr[j]) > 0)
{
t=pstr[j];
pstr[j]=pstr[i];
pstr[i]=t;
}
}
}
}
用指向指针的指针的方法对5个字符串排序后输出。(2)
最新推荐文章于 2021-12-17 00:04:15 发布