// 字符串排序
#include <stdio.h>
#include <string.h>
#define MAXLEN 100
#define N 5
void StringSort(char s[][MAXLEN], int n);
int main()
{
char s[N][MAXLEN];
int i;
printf("请输入5个字符串:\n");
for(i=0;i<N;i++)
{
scanf("%s",&s[i]);
}
StringSort(s,N);
printf("字符串排序后:\n");
for(i=0;i<N;i++)
{
printf("%s\n",s[i]);
}
return 0;
}
void StringSort(char s[][MAXLEN], int n)
{
int i,j;
char temp[MAXLEN];
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(strcmp(s[j],s[j+1])>0)
{
strcpy(temp,s[j]);
strcpy(s[j],s[j+1]);
strcpy(s[j+1],temp);
}
}
}
}