C语言程序如下:
#include <
stdio.h>
#include <
string.h>
#include <malloc.h>
#define N 100
#define MAX 100
void sort(char** str,int n)
{
for(int i = 0;i < n - 1;i++)
{
for(int j = 0;j < n - 1- i;j++)
{
if(strcmp(str[j], str[j + 1]) > 0)
{
char *temp = str[j];
str[j] = str[j + 1];
str[j + 1] = temp;
}
}
}
}
void main()
{
char *a[N];
int n;
int i;
printf("n : ");
scanf("%d", &n);
for(i=0; i<n; i++)
{
a[i] = (char *)malloc(MAX * sizeof(char));
scanf("%s", a[i]);
}
sort(a,n);
for(i = 0;i < n;i++)
{
puts(a[i]);
}
}