帮个忙,看看这题。

来源:百度知道 编辑:UC知道 时间:2024/05/07 12:41:05
写一个函数,用来对一个字符串数组从小到大排序

用字符串比较函数

#include<string.h>

void arrange(char *arry[],int len)
{
char *temp;

for(int i=0;i<len-1;i++)
{
for(int j=0;j<(len-1)-i;j++)
{
if(strcmp(arry[j],arry[j+1])>0)
{
temp=arry[j+1];
arry[j+1]=arry[j];
arry[j]=temp;
}
}
}
}

/*
原型:extern int strcmp(char *s1,char * s2);
用法:#include <string.h>
功能:比较字符串s1和s2。
说明:
当s1<s2时,返回值<0
当s1=s2时,返回值=0
当s1>s2时,返回值>0
*/