[求助]字符串的排列问题
											假如输入5个字符串,按照从大到小的顺序排列.例如排列 mnb vcc ljh dss erw 我在想应该要调用strcmp函数吧?可能的话想用指针来做~
假如输入5个字符串,按照从大到小的顺序排列.例如排列 mnb vcc ljh dss erw 我在想应该要调用strcmp函数吧?可能的话想用指针来做~
 2006-12-13 13:22
	    2006-12-13 13:22
  [CODE]#include <stdio.h>
#include <string.h>
void sort(char (*str)[20])
{
    char *p,tmp[20];
    int i,j;
    for(i=0;i<3;i++)
    {
        p=str[i];
        for(j=i+1;j<4;j++)
            if(strcmp(p,str[j])>0)
                p=str[j];
        if(strcmp(p,str[i]))
        {
            strcpy(tmp,p);
            strcpy(p,str[i]);
            strcpy(str[i],tmp);
        }
    }
}
int main()
{
    char str[5][20]={"mnb","vcc","ljh","dss","erw"};
    int i;
    sort(str);
    for(i=0;i<4;i++)
        printf("%s\n",str[i]); 
    return 0;
}[/CODE]
 2006-12-13 13:34
	    2006-12-13 13:34
   2006-12-13 13:38
	    2006-12-13 13:38
   2006-12-14 21:55
	    2006-12-14 21:55
   2006-12-15 22:38
	    2006-12-15 22:38
   2006-12-16 00:17
	    2006-12-16 00:17
   2006-12-16 13:50
	    2006-12-16 13:50